Help with f.select

I have this code in my new view:

Product
<% @products.each do |product| %> > <%= product.name%> <% end %>

I have many products, so when I click to show my products and then
select one, I obtain a huge list. I would like only to show 5 or more of
my list and then have a sidebar in this list so I can roll down the
list and select one.

John S. wrote:

I have this code in my new view:

Product
<% @products.each do |product| %> > <%= product.name%> <% end %>

I have many products, so when I click to show my products and then
select one, I obtain a huge list. I would like only to show 5 or more of
my list and then have a sidebar in this list so I can roll down the
list and select one.

Well this should be easy to do.

option 1) do a limit on your find operation:

@products = Product.find(:all, :limit => 5)

or option 2) simply grab the first 5 from the array

@products = Product.find(:all, :limit => 5)
first_five = @products[0…4]

either way that will get you the first five to display.

Nathan E. wrote:

John S. wrote:

I have this code in my new view:

Product
<% @products.each do |product| %> > <%= product.name%> <% end %>

I have many products, so when I click to show my products and then
select one, I obtain a huge list. I would like only to show 5 or more of
my list and then have a sidebar in this list so I can roll down the
list and select one.

Well this should be easy to do.

option 1) do a limit on your find operation:

@products = Product.find(:all, :limit => 5)

or option 2) simply grab the first 5 from the array

@products = Product.find(:all, :limit => 5)
first_five = @products[0…4]

either way that will get you the first five to display.

Thanks, but I mean another thing. If i do what you suggested, I only
display de 5 first ones, and never display the other ones. I want to
display only five and with a bar be able to scroll down and see the
other ones.

I will give it another try. Are you referring to wanting a paginated
list?

http://rock.errtheblog.com/will_paginate

Pagination basically displays only 5 at once or whatever, but allows you
to shift and see all of them by browsing through pages…

if I missed it again I will let someone else answer

Nathan E. wrote:

I will give it another try. Are you referring to wanting a paginated
list?

http://rock.errtheblog.com/will_paginate

Pagination basically displays only 5 at once or whatever, but allows you
to shift and see all of them by browsing through pages…

if I missed it again I will let someone else answer

Ok, it was another problem, but it’s already solved. Thanks for your
help.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs