Hello, I''ve done ==class HomeController < ApplicationController def index @country = Country.find(:all, :include => "cities") end end ==And rhtml is: == <% @country.each do |country| %> <h1><%= country.name %></h1> <% country.cities.each do |city| %> - <%= link_to city.name, :action => "city/view", :id => city.id %></li> <% end %> <% end %> ==I have over 200 _counties_. How can I print counties #0-22, counties #23-44 etc (with cities inside). Thanks. -- Posted via http://www.ruby-forum.com/.
Check out the documentation on Pagination On 5/31/06, Vladislav Gorodetskiy <oladywek@gmail.com> wrote:> Hello, > > I''ve done > ==> class HomeController < ApplicationController > def index > @country = Country.find(:all, :include => "cities") > end > end > ==> And rhtml is: > > ==> <% @country.each do |country| %> > <h1><%= country.name %></h1> > <% country.cities.each do |city| %> > - <%= link_to city.name, :action => "city/view", :id => city.id > %></li> > <% end %> > <% end %> > ==> I have over 200 _counties_. How can I print counties #0-22, counties > #23-44 etc (with cities inside). > > Thanks. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Carl-Johan Kihlbom wrote:> Check out the documentation on PaginationI need to show all these coutries on single page. It''s not a pagination... -- Posted via http://www.ruby-forum.com/.
> I have over 200 _counties_. How can I print counties #0-22, counties > #23-44 etc (with cities inside).You could use Array#in_groups_of in Rails'' core extensions to do this: <% @countries.in_groups_of(22) do |group_of_countries| %> <% group_of_countries.each do |country| %> <%= country.name %> <% end %> <% end %> in_groups_of doesn''t appear to be in the online api documentation for some reason, so maybe you''ll have to look in [your gems installation]/activesupport-[whatever version]/lib/ active_support/core_ext/array.rb -- Michael Daines http://www.mdaines.com
On 5/31/06, Vladislav Gorodetskiy <oladywek@gmail.com> wrote:> Carl-Johan Kihlbom wrote: > > Check out the documentation on Pagination > > I need to show all these coutries on single page. It''s not a > pagination... >Check out ''in_groups_of'': http://weblog.rubyonrails.org/articles/2006/03/01/new-in-rails-enumerable-group_by-and-array-in_groups_of
Michael Daines wrote:> in_groups_of doesn''t appear to be in the online api documentation for > some reasonWhen they #:nodoc: a method like that, is that their way of saying, "This is an internal thingamajigger, and not guaranteed to work the same in the next version"?
> When they #:nodoc: a method like that, is that their way of saying, > "This is an internal thingamajigger, and not guaranteed to work the > same in the next version"?I don''t think it''s supposed to be considered internal. It''s mentioned in the weblog, and the only change so far keeps the current functionality. (Now if you don''t pass a block it returns the grouped arrays instead of yielding them.) All in all, in_groups_of is pretty unsurprising, I think. http://weblog.rubyonrails.org/articles/2006/03/01/new-in-rails- enumerable-group_by-and-array-in_groups_of http://dev.rubyonrails.org/changeset/4345 You can always put this in your lib if you want: http://redhanded.hobix.com/bits/matchingIntoMultipleAssignment.html -- Michael Daines http://www.mdaines.com
Hm... I tried <% @topic.in_groups_of(3) do |group_of_topics| %> <% group_of_topics.each do |topic| %> <hr /> <h2><%= topic.name %></h2> <ul> <% topic.categories.each do |category| %> <li><%= link_to category.name, :action => "view", :id => category.id %></li> <% end %> </ul> <% end %> <% end %> but I have =You have a nil object when you didn''t expect it! =The error occured while evaluating nil.name My controller is def index @topic = Topic.find(:all, :include => "categories") end ...... -- Posted via http://www.ruby-forum.com/.