Forum: Ruby on Rails Scaffolding Results Format

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jay C. (Guest)
on 2009-05-27 15:16
Hi Everyone,

I built a scaffold and I'm having trouble getting results properly
formatted. (I need to get the data into multiple columns instead of just
one big column) I can't get all of my CSS to work properly in
scaffold.css, layout/books.rhtml, or the books/index.rhtml.erb Anyways,
maybe you have a suggestion.


Default view (127.0.0.1:3000/books)


Title           Abstract
Book One     Book One Abstract        Show     Edit     Destroy
Book Two     Book Two Abstract        Show      Edit    Destroy
Book Three   Book Three Abstract      Show      Edit    Destroy


-------------------------------------------------------------------
View I would like to see displayed (127.0.0.1:3000/books):


Book One                         Book Two                     Book Three
Book One Abstract           Book Two Abstract         Book Three
Abstract
Show Edit Destroy           Show Edit Destroy         Show Edit Destroy


---------------------------------------------------------------------


I've tried editing scaffold.css, layouts/books.rhtml.erb, and
books/index.rhtml.erb but can only achieve this result:


Book One
Book One Abstract
Show Edit Destroy
Book Two
Book Two Abstract
Show Edit Destroy
Book Three
Booth Three Abstract
Show Edit Destroy



------------------------------------------------

Am I missing something in books_controller.rb?  Thanks for your help!
Conrad T. (Guest)
on 2009-05-27 15:29
(Received via mailing list)
On Wed, May 27, 2009 at 4:16 AM, Jay C. <
removed_email_address@domain.invalid> wrote:

> Default view (127.0.0.1:3000/books)
>
>
> Book One                         Book Two                     Book Three
> Book One Abstract           Book Two Abstract         Book Three
> Abstract
> Show Edit Destroy           Show Edit Destroy         Show Edit Destroy


The presentation of the output you would like to have is very confusing
at best.  For example, what does edit and destroy links do at the bottom
of each table?  Do they operate on all of the entries?  You might want
to
clarify what you're really trying to do with this type of structure.

-Conrad

[snip]
Jay C. (Guest)
on 2009-05-27 15:46
Conrad T. wrote:
> On Wed, May 27, 2009 at 4:16 AM, Jay C. <
> removed_email_address@domain.invalid> wrote:
>
>> Default view (127.0.0.1:3000/books)
>>
>>
>> Book One                         Book Two                     Book Three
>> Book One Abstract           Book Two Abstract         Book Three
>> Abstract
>> Show Edit Destroy           Show Edit Destroy         Show Edit Destroy
>
>
> The presentation of the output you would like to have is very confusing
> at best.  For example, what does edit and destroy links do at the bottom
> of each table?  Do they operate on all of the entries?  You might want
> to
> clarify what you're really trying to do with this type of structure.
>
> -Conrad
>
> [snip]

-------------------------------------------------------------------------
By default, scaffold displays data into rows it seems. Disregard the
"Show" "Edit" "Destroy" links as they are just the generic actions
produced by creating the scaffold. All I'm trying to do is get the
127.0.0.1:books to display the data in multiple columns instead of just
one.

 Book One              Book Two            Book Three
 Book One Abstract     Book Two Abstract   Book Three Abstract

 Book Four             Book Five           Book Six
 Book Four Abstract    Book Five Abstract  Book Six Abstract
Ar C. (Guest)
on 2009-05-28 01:20
Take a look at the in_groups_of method for your list processing in the
view...

@books.in_groups_of(3) do |group|
  start row
  group.each.do |book|
    start column
    book.title + '</br>' + book.abstract
    end column
  end
  end row
end

or something like that...
Jay C. (Guest)
on 2009-05-28 16:35
Ar Chron wrote:
> Take a look at the in_groups_of method for your list processing in the
> view...
>
> @books.in_groups_of(3) do |group|
>   start row
>   group.each.do |book|
>     start column
>     book.title + '</br>' + book.abstract
>     end column
>   end
>   end row
> end
>
> or something like that...

Thanks Ar Chron! That is the right method. Railscast #28 discusses this
in_groups_of method for anyone encountering the same problem.
This topic is locked and can not be replied to.