vidja@rombalboni.demon.nl
2006-Jan-20 23:45 UTC
[Rails] [newbie]how to use link_to to link to another controller?
I am just diving into Rails and I am a bit puzzled by the link_to function. am writing an app to display my photographs in categories. My application layout has a sidebar to show a menu with categories from the categories table in the database (like in taken from the tutorials), to be shown on every page. I managed to get a global @menu_categories object that keeps track of all the categories that should pop up in the menu using in the application controller def initialize @menu_categories=Category.find_all end Now, if I iterate over these menu categories in the application template <% for menu_category in @menu_categories %> <% link_to menu_category.category, :action =>''list_photos'',:id =>menu_category%></a><br /> <% end %> I get the following links: http://192.168.1.100:8000/categories/list_photos/3 (when in categories conroller) http://192.168.1.100:8000/photos/list_photos/3 (when in photos controller) What I want however is to have the second link always, regardles where I am in the app. So How do I instruct the link_to helper to always link to a specific controller in the app? Cheers VidJa
Ben Reubenstien
2006-Jan-20 23:55 UTC
[Rails] [newbie]how to use link_to to link to another controller?
<%= link_to :controller => "category", :action => "list_photos", :id => IDHERE %> ~Ben On 1/20/06, vidja@rombalboni.demon.nl <vidja@rombalboni.demon.nl> wrote:> > I am just diving into Rails and I am a bit puzzled by the link_to > function. > > am writing an app to display my photographs in categories. My application > layout > has a sidebar to show a menu with categories from the categories table in > the > database (like in taken from the tutorials), to be shown on every page. > > I managed to get a global @menu_categories object that keeps track of all > the > categories that should pop up in the menu using in the application > controller > def initialize > @menu_categories=Category.find_all > end > > Now, if I iterate over these menu categories in the application template > <% for menu_category in @menu_categories %> > <% link_to menu_category.category, :action =>''list_photos'',:id > =>menu_category%></a><br /> > <% end %> > > I get the following links: > http://192.168.1.100:8000/categories/list_photos/3 (when in categories > conroller) > http://192.168.1.100:8000/photos/list_photos/3 (when in photos controller) > > What I want however is to have the second link always, regardles where I > am in > the app. So How do I instruct the link_to helper to always link to a > specific > controller in the app? > > Cheers VidJa > > > > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Ben Reubenstein http://www.benr75.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060120/1fc20196/attachment.html
Dylan Stamat
2006-Jan-20 23:58 UTC
[Rails] [newbie]how to use link_to to link to another controller?
Possibly: <% link_to menu_category.category, {:controller => ''your_controller'', :action =>''list_photos'', :id=>menu_category}%> On 1/20/06, vidja@rombalboni.demon.nl <vidja@rombalboni.demon.nl> wrote:> > I am just diving into Rails and I am a bit puzzled by the link_to > function. > > am writing an app to display my photographs in categories. My application > layout > has a sidebar to show a menu with categories from the categories table in > the > database (like in taken from the tutorials), to be shown on every page. > > I managed to get a global @menu_categories object that keeps track of all > the > categories that should pop up in the menu using in the application > controller > def initialize > @menu_categories=Category.find_all > end > > Now, if I iterate over these menu categories in the application template > <% for menu_category in @menu_categories %> > <% link_to menu_category.category, :action =>''list_photos'',:id > =>menu_category%></a><br /> > <% end %> > > I get the following links: > http://192.168.1.100:8000/categories/list_photos/3 (when in categories > conroller) > http://192.168.1.100:8000/photos/list_photos/3 (when in photos controller) > > What I want however is to have the second link always, regardles where I > am in > the app. So How do I instruct the link_to helper to always link to a > specific > controller in the app? > > Cheers VidJa > > > > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060120/8dadfc7f/attachment.html
Ben Reubenstien
2006-Jan-21 00:00 UTC
[Rails] [newbie]how to use link_to to link to another controller?
Dylan has it ... forgot to include the "title" field... Be sure to use the API Docs. They are very helpful: http://api.rubyonrails.com/classes/ActionView/Helpers/UrlHelper.html#M000332< link_to info... On 1/20/06, Dylan Stamat <dylans@gmail.com> wrote:> > Possibly: > <% link_to menu_category.category, {:controller => ''your_controller'', > :action =>''list_photos'', :id=>menu_category}%> > > > On 1/20/06, vidja@rombalboni.demon.nl <vidja@rombalboni.demon.nl > wrote: > > > > I am just diving into Rails and I am a bit puzzled by the link_to > > function. > > > > am writing an app to display my photographs in categories. My > > application layout > > has a sidebar to show a menu with categories from the categories table > > in the > > database (like in taken from the tutorials), to be shown on every page. > > > > I managed to get a global @menu_categories object that keeps track of > > all the > > categories that should pop up in the menu using in the application > > controller > > def initialize > > @menu_categories=Category.find_all > > end > > > > Now, if I iterate over these menu categories in the application template > > <% for menu_category in @menu_categories %> > > <% link_to menu_category.category, :action =>''list_photos'',:id > > =>menu_category%></a><br /> > > <% end %> > > > > I get the following links: > > http://192.168.1.100:8000/categories/list_photos/3 (when in categories > > conroller) > > http://192.168.1.100:8000/photos/list_photos/3 (when in photos > > controller) > > > > What I want however is to have the second link always, regardles where I > > am in > > the app. So How do I instruct the link_to helper to always link to a > > specific > > controller in the app? > > > > Cheers VidJa > > > > > > > > > > > > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- Ben Reubenstein http://www.benr75.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060121/98de61c1/attachment-0001.html
VidJa
2006-Jan-21 09:35 UTC
[Rails] Re: [newbie]how to use link_to to link to another controller
Thanks Ben and Dylan, it works. I have been looking at the API docs before, but actually I can''t find the info for the controller option. After some digging this morning I found that the link in the link_to section probably should lead to http://api.rubyonrails.com/classes/ActionController/Base.html#M000174 instead of http://api.rubyonrails.com/classes/ActionView/Helpers/UrlHelper.html#M000304 since that is where the options are eplained. Maybe that was the reason I couldn''t find it? Anyway, many thanks. Ruby aint bad as a the second language after php to learn Ben Reubenstien wrote:> Dylan has it ... forgot to include the "title" field... > > Be sure to use the API Docs. They are very helpful: > > http://api.rubyonrails.com/classes/ActionView/Helpers/UrlHelper.html#M000332< > link_to info...-- Posted via http://www.ruby-forum.com/.