I have gerated a scaffold_resource for "news" like so: script/generate scaffold_resource news <fields> I have also added a route to routes.rb map.resources :news I have an application-wide layout that contains a menu with the entry: <%= link_to("News", news_path) %> Now, the odd thing is that this generates <applicationurl>/news from most pages, but the same entry points to <applicationurl>/news/1 from within the news/1 page and from within the edit page for news 1. Similar it points to <applicationurl>/2 from the show and edit pages for news 2. When a news_path occurs anywhere on an news edit or show page, it does not link to the index action but to the show action for that specific record. I have a couple of other models/views/controllers which all work fine, only the news part shows this odd (and definitely wrong) behavior. I tried to add :singular => :news to the route definition, but that did not help. Is this a bug in RoR? -- 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 -~----------~----~----~----~------~----~------~--~---
Roman Hausner wrote:> I have gerated a scaffold_resource for "news" like so: > > script/generate scaffold_resource news <fields> > > I have also added a route to routes.rb > > map.resources :news > > I have an application-wide layout that contains a menu with the entry: > > <%= link_to("News", news_path) %> > > Now, the odd thing is that this generates <applicationurl>/news from > most pages, but the same entry points to <applicationurl>/news/1 from > within the news/1 page and from within the edit page for news 1. Similar > it points to <applicationurl>/2 from the show and edit pages for news 2. > When a news_path occurs anywhere on an news edit or show page, it does > not link to the index action but to the show action for that specific > record. > > I have a couple of other models/views/controllers which all work fine, > only the news part shows this odd (and definitely wrong) behavior. > > I tried to add :singular => :news to the route definition, but that did > not help. > > Is this a bug in RoR?Show us the relevant parts of your code please. When I do scaffold_resource it works as expected. -- Cheers, - Jacob Atzen --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2007-Jun-08 21:23 UTC
Re: Strange error - bug in RoR?
Hi -- On Fri, 8 Jun 2007, Roman Hausner wrote:> > I have gerated a scaffold_resource for "news" like so: > > script/generate scaffold_resource news <fields> > > I have also added a route to routes.rb > > map.resources :news > > I have an application-wide layout that contains a menu with the entry: > > <%= link_to("News", news_path) %> > > Now, the odd thing is that this generates <applicationurl>/news from > most pages, but the same entry points to <applicationurl>/news/1 from > within the news/1 page and from within the edit page for news 1. Similar > it points to <applicationurl>/2 from the show and edit pages for news 2. > When a news_path occurs anywhere on an news edit or show page, it does > not link to the index action but to the show action for that specific > record. > > I have a couple of other models/views/controllers which all work fine, > only the news part shows this odd (and definitely wrong) behavior. > > I tried to add :singular => :news to the route definition, but that did > not help. > > Is this a bug in RoR?No. There can only be one method called news_path, and either it is the singular named route or the plural one. I would recommend: map.resources :news, :singular => "news_item" Then you can do: <%= link_to item.title, news_item_path(item) %> <%= link_to "All news", news_path %> That will separate the singular from the plural, and it actually makes more sense linguistically too. David -- Q. What is THE Ruby book for Rails developers? A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf) Q. Where can I get Ruby/Rails on-site training, consulting, coaching? A. Ruby Power and Light, LLC (http://www.rubypal.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 -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2007-Jun-08 21:31 UTC
Re: Strange error - bug in RoR?
Hi -- On Fri, 8 Jun 2007, Jacob Atzen wrote:> > Roman Hausner wrote: >> I have gerated a scaffold_resource for "news" like so: >> >> script/generate scaffold_resource news <fields> >> >> I have also added a route to routes.rb >> >> map.resources :news >> >> I have an application-wide layout that contains a menu with the entry: >> >> <%= link_to("News", news_path) %> >> >> Now, the odd thing is that this generates <applicationurl>/news from >> most pages, but the same entry points to <applicationurl>/news/1 from >> within the news/1 page and from within the edit page for news 1. Similar >> it points to <applicationurl>/2 from the show and edit pages for news 2. >> When a news_path occurs anywhere on an news edit or show page, it does >> not link to the index action but to the show action for that specific >> record. >> >> I have a couple of other models/views/controllers which all work fine, >> only the news part shows this odd (and definitely wrong) behavior. >> >> I tried to add :singular => :news to the route definition, but that did >> not help. >> >> Is this a bug in RoR? > > Show us the relevant parts of your code please. When I do > scaffold_resource it works as expected.I agree that it does what''s expected, but that''s not what the OP wants :-) If you look at views/news/show.rhtml, as produced by the scaffolding, you''ll see: <%= link_to ''Edit'', edit_news_path(@news) %> | <%= link_to ''Back'', news_path %> That "Back" link would normally link to the index action (a plural GET), but in this case, news_path has been taken up by the singular, and the :id field is inferred from the current environment. So it''s equivalent to: news_path(2) # for example, if params[:id] is current 2 and if you click on it, it takes you back to the show page you''re already on. That''s why you need to differentiate between singular and plural news. (As tested on Rails 1.2.3.) David -- Q. What is THE Ruby book for Rails developers? A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf) Q. Where can I get Ruby/Rails on-site training, consulting, coaching? A. Ruby Power and Light, LLC (http://www.rubypal.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 -~----------~----~----~----~------~----~------~--~---
unknown wrote:> I agree that it does what''s expected, but that''s not what the OP wants > :-) If you look at views/news/show.rhtml, as produced by the > scaffolding, you''ll see: > > <%= link_to ''Edit'', edit_news_path(@news) %> | > <%= link_to ''Back'', news_path %> > > That "Back" link would normally link to the index action (a plural > GET), but in this case, news_path has been taken up by the singular, > and the :id field is inferred from the current environment. So it''s > equivalent to: > > news_path(2) # for example, if params[:id] is current 2 > > and if you click on it, it takes you back to the show page you''re > already on. > > That''s why you need to differentiate between singular and plural news. > > (As tested on Rails 1.2.3.)Thank you for the clarification -- i was puzzled by the implicit passing of id, which changes the meaning of news_path depending on where it appears. That did not seem intuitively right to me. In any case, I have chosen to avoid the confusion and changed the naming alltogether. -- 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 -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2007-Jun-09 17:02 UTC
Re: Strange error - bug in RoR?
Hi -- On Sat, 9 Jun 2007, Roman Hausner wrote:> > unknown wrote: >> I agree that it does what''s expected, but that''s not what the OP wants >> :-) If you look at views/news/show.rhtml, as produced by the >> scaffolding, you''ll see: >> >> <%= link_to ''Edit'', edit_news_path(@news) %> | >> <%= link_to ''Back'', news_path %> >> >> That "Back" link would normally link to the index action (a plural >> GET), but in this case, news_path has been taken up by the singular, >> and the :id field is inferred from the current environment. So it''s >> equivalent to: >> >> news_path(2) # for example, if params[:id] is current 2 >> >> and if you click on it, it takes you back to the show page you''re >> already on. >> >> That''s why you need to differentiate between singular and plural news. >> >> (As tested on Rails 1.2.3.) > > Thank you for the clarification -- i was puzzled by the implicit passing > of id, which changes the meaning of news_path depending on where it > appears. That did not seem intuitively right to me.It''s really the other way around: because news_path is a singular resource route, and it requires an :id value, it makes use of the existing value. news_path itself doesn''t change. If you try to put this in index.rhtml: <%= link_to "Attempting link back to showing all news", news_path %> you''ll get an error, because it will be trying to execute news_path but unable to find an :id value. (If my description isn''t consistent with what you''re getting, I''d be interested to hear about it.)> In any case, I have chosen to avoid the confusion and changed the naming > alltogether.That''s definitely the best plan. David -- Q. What is THE Ruby book for Rails developers? A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf) Q. Where can I get Ruby/Rails on-site training, consulting, coaching? A. Ruby Power and Light, LLC (http://www.rubypal.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 -~----------~----~----~----~------~----~------~--~---