REST/path question... routes.rb map.resources :continent do |continent| continent.resources :land do |land| land.resources :destination end end Show.rhtml of land(countrie) controller, to show the (belongs_to) destinations <h2>Destinations</h2> <ul> <% @Destination.each do |destination| %> <li><%= link_to destination.naam, continent_land_destination_path(@land.continent, @land, destinations)%></li> <% end %> </ul> problem: On my germany-page http://www.goedkoop-vliegen.nu/werelddeel/europa/land/duitsland It generates all my destinations...in this url structure..(atlanta) http://www.goedkoop-vliegen.nu/werelddeel/europa/land/duitsland/bestemming/atlanta The url isn''t mapping (example: atlanta) to http://www.goedkoop-vliegen.nu/werelddeel/noord-amerika/land/verenigde-staten/bestemming/atlanta Which parameters must i define in link_to destination.naam, continent_land_destination_path(paramaters,parameters ect) ? Grtz..remco -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> <% @Destination.each do |destination| %>shouldn''t that be <% @land.destinations.each do |destination| %> ? I guess Rails interprets @Destination as Destination and loops through _all_ Destination records. It''s hard to say without the controller method, but @land doesn''t seem to be linked to destination in your code. Remco Zwaan wrote:> REST/path question... > > routes.rb > map.resources :continent do |continent| > continent.resources :land do |land| > land.resources :destination > end > end > > Show.rhtml of land(countrie) controller, to show the (belongs_to) > destinations > <h2>Destinations</h2> > <ul> > <% @Destination.each do |destination| %> > <li><%= link_to destination.naam, > continent_land_destination_path(@land.continent, @land, > destinations)%></li> > <% end %> > </ul> > > problem: > On my germany-page > http://www.goedkoop-vliegen.nu/werelddeel/europa/land/duitsland > > It generates all my destinations...in this url structure..(atlanta) > > http://www.goedkoop-vliegen.nu/werelddeel/europa/land/duitsland/bestemming/atlanta > > The url isn''t mapping (example: atlanta) to > > http://www.goedkoop-vliegen.nu/werelddeel/noord-amerika/land/verenigde-staten/bestemming/atlanta > > Which parameters must i define in > > link_to destination.naam, > continent_land_destination_path(paramaters,parameters ect) ? > > Grtz..remco--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
First, I''d suggest using lower case unless you''re using a class name (@Destination => @destination). How did you set @destination? It would appear that your controller should have something like: @land = Land.find(...) @destinations = @land.destinations.find(:all, :order=>:naam) Otherwise, your view looks okay except for a possible typo (check the link_to call, you refer to destinations but have not defined it): <h2>Destinations in <%= h destination.naam %></h2> <ul> <% @destinations.each do |destination| %> <li><%= link_to destination.naam, continent_land_destination_path(@land.continent, @land, destination)%></li> <% end %> </ul> On May 13, 5:06 am, Remco Zwaan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> REST/path question... > > routes.rb > map.resources :continent do |continent| > continent.resources :land do |land| > land.resources :destination > end > end > > Show.rhtml of land(countrie) controller, to show the (belongs_to) > destinations > <h2>Destinations</h2> > <ul> > <% @Destination.each do |destination| %> > <li><%= link_to destination.naam, > continent_land_destination_path(@land.continent, @land, > destinations)%></li> > <% end %> > </ul> > > problem: > On my germany-pagehttp://www.goedkoop-vliegen.nu/werelddeel/europa/land/duitsland > > It generates all my destinations...in this url structure..(atlanta) > > http://www.goedkoop-vliegen.nu/werelddeel/europa/land/duitsland/beste... > > The url isn''t mapping (example: atlanta) to > > http://www.goedkoop-vliegen.nu/werelddeel/noord-amerika/land/verenigd... > > Which parameters must i define in > > link_to destination.naam, > continent_land_destination_path(paramaters,parameters ect) ? > > Grtz..remco > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
AndyV wrote:> First, I''d suggest using lower case unless you''re using a class name > (@Destination => @destination). > > How did you set @destination? It would appear that your controller > should have something like: > > @land = Land.find(...) > @destinations = @land.destinations.find(:all, :order=>:naam) > > Otherwise, your view looks okay except for a possible typo (check the > link_to call, you refer to destinations but have not defined it): > > <h2>Destinations in <%= h destination.naam %></h2> > <ul> > <% @destinations.each do |destination| %> > <li><%= link_to destination.naam, > continent_land_destination_path(@land.continent, @land, > destination)%></li> > <% end %> > </ul> > > On May 13, 5:06 am, Remco Zwaan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Hi... The url structure is not good if i use this code..check > http://www.goedkoop-vliegen.nu/werelddeel/afrika/land/kenia The continent(werelddeel)and land(countrie) is not changing...... The code for continents works fine for continents.. http://www.goedkoop-vliegen.nu/werelddeel <h2>Landen</h2> <ul> <% @landen.each do |land| %> <li><%= link_to land.naam, continent_land_path(land.continent, land)%></li> <% end %> </ul> When i try this <h2>destinations</h2> <ul> <% @destinations.each do |destination| %> <li><%= link_to land.naam, continent_land_destination_path(land.continent, land, destinations)%></li> <% end %> </ul> I get the error message undefined local variable or method `land'' for #<ActionView::Base:0xb79f6e44> This is my setup: map.resources :continent do |continent | continent .resources :land do |land| land.resources :destination end end class Destination < ActiveRecord::Base has_many :land, :foreign_key => "landcode" set_table_name "bestemmingen" set_primary_key "bestemming_id" has_permalink :stad_zoeknaam def to_param stad_zoeknaam end end class Land < ActiveRecord::Base belongs_to :continent, :foreign_key => "werelddeel_id" has_many :destination, :foreign_key => "landcode" set_table_name "landen" set_primary_key "landcode" has_permalink :land_zoeknaam def to_param land_zoeknaam end end Grtz..remco -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I was assuming that you were displaying the destinations for a specific land. Your controller should be setting an instance variable (@land) and you should be using that instance variable in the link_to call (as shown above). In the code that you''ve shown in your last post you are using a local variable (land) rather than an instance variable (@land). Two other observations. First, I''m not familiar with the language but it appears from your posts that landen is the plural of land. If so, your nested routes might be more natural as: map.resources :continent do |continent | continent .resources :landen do |land| land.resources :destination end end Second, there is a growing sentiment toward avoiding nesting resources too deeply. The primary argument in favor of nesting routes is to provide the proper context for some ''belongs_to'' (child) relationship. Nesting beyond a certain level becomes a burden to the developer (the xxx_yyy_zzz_aaa_path statements are too long) and the ''pretty urls'' are pretty only in the sense of being ''pretty long''. All that to say you might consider breaking up your nesting if you get tired of all that keying: map.resources :continent do |continent | continent.resources :landen end map.resources :landen do |land| land.resources :destination end You may be fine where you are right now, but I would not recommend going any deeper with your nesting. On May 14, 3:10 am, Remco Zwaan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> AndyV wrote: > > First, I''d suggest using lower case unless you''re using a class name > > (@Destination => @destination). > > > How did you set @destination? It would appear that your controller > > should have something like: > > > @land = Land.find(...) > > @destinations = @land.destinations.find(:all, :order=>:naam) > > > Otherwise, your view looks okay except for a possible typo (check the > > link_to call, you refer to destinations but have not defined it): > > > <h2>Destinations in <%= h destination.naam %></h2> > > <ul> > > <% @destinations.each do |destination| %> > > <li><%= link_to destination.naam, > > continent_land_destination_path(@land.continent, @land, > > destination)%></li> > > <% end %> > > </ul> > > > On May 13, 5:06 am, Remco Zwaan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > Hi... > > The url structure is not good if i use this code..check >http://www.goedkoop-vliegen.nu/werelddeel/afrika/land/kenia > > The continent(werelddeel)and land(countrie) is not changing...... > > The code for continents works fine for continents..http://www.goedkoop-vliegen.nu/werelddeel > <h2>Landen</h2> > <ul> > <% @landen.each do |land| %> > <li><%= link_to land.naam, continent_land_path(land.continent, > land)%></li> > <% end %> > </ul> > > When i try this > <h2>destinations</h2> > <ul> > <% @destinations.each do |destination| %> > <li><%= link_to land.naam, > continent_land_destination_path(land.continent, land, > destinations)%></li> > <% end %> > </ul> > > I get the error message > > undefined local variable or method `land'' for > #<ActionView::Base:0xb79f6e44> > > This is my setup: > > map.resources :continent do |continent | > continent .resources :land do |land| > land.resources :destination > end > end > > class Destination < ActiveRecord::Base > has_many :land, :foreign_key => "landcode" > set_table_name "bestemmingen" > set_primary_key "bestemming_id" > has_permalink :stad_zoeknaam > > def to_param > stad_zoeknaam > end > > end > > class Land < ActiveRecord::Base > belongs_to :continent, :foreign_key => "werelddeel_id" > has_many :destination, :foreign_key => "landcode" > set_table_name "landen" > set_primary_key "landcode" > > has_permalink :land_zoeknaam > > def to_param > land_zoeknaam > end > end > > Grtz..remco > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
AndyV wrote:> I was assuming that you were displaying the destinations for a > specific land. Your controller should be setting an instance variable > (@land) and you should be using that instance variable in the link_to > call (as shown above). In the code that you''ve shown in your last > post you are using a local variable (land) rather than an instance > variable (@land). > > Two other observations. First, I''m not familiar with the language but > it appears from your posts that landen is the plural of land. If so, > your nested routes might be more natural as: > > map.resources :continent do |continent | > continent .resources :landen do |land| > land.resources :destination > end > end > > > Second, there is a growing sentiment toward avoiding nesting resources > too deeply. The primary argument in favor of nesting routes is to > provide the proper context for some ''belongs_to'' (child) > relationship. Nesting beyond a certain level becomes a burden to the > developer (the xxx_yyy_zzz_aaa_path statements are too long) and the > ''pretty urls'' are pretty only in the sense of being ''pretty long''. > All that to say you might consider breaking up your nesting if you get > tired of all that keying: > > map.resources :continent do |continent | > continent.resources :landen > end > > map.resources :landen do |land| > land.resources :destination > end > > You may be fine where you are right now, but I would not recommend > going any deeper with your nesting. > > On May 14, 3:10 am, Remco Zwaan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>He Andy.. You''re reply (thanks!!) and analysing my log file....put me in the wright direction..and it works now...this is my final code. Land-Controller: @destination= destination.find_all_by_landcode(@land.landcode) Land-View: <% @destinations.each do |destination| %> <li><%= link_to destination.naam, continent_land_destination_path(@land.continent, @land, destination)%></li> <% end %> Land-Model: class Land < ActiveRecord::Base belongs_to :continent, :foreign_key => "werelddeel_id" has_many :destination, :foreign_key => "landcode" set_table_name "landen" set_primary_key "landcode" has_permalink :land_zoeknaam def to_param land_zoeknaam end end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---