Alright, I''m a newbie so I''m not even sure if the subject of this post is accurate, but here is what I want to do: The menu items that I want to show on every page of my site are stored in my database. Each of them is an activity, so they are stored in the activities database and I have them scaffolded to Activity. This all works great! The problem is in my layout I want to get all these activities and link to their "show" action from the menu. Here is a snippet of code that I learned from reading the tutorials: <% @activities = Activity.find_all %> <% @activities.each do |activity| %> <TR><TD> <%= link_to activity.name, :action => "show", :id => activity.id %> <% end %> Of course, if I''m looking at this from my home page, the links all point to: mysite.com/home/show/1 (for example) when I want them to point to mysite.com/activities/show/1 I''ve tried to replace "show" with Activity.show, but Rails says that the Activity class doesn''t have a show method. I''ve even tried ../activities/show, but that didn''t work either. Either I''m missing something really easy, or you''re not supposed to use ruby in your layouts...I''m guessing it''s the former! Thanks for any help you can give. Also, just so I''m not here asking more stupid questions, can anyone enlighten me to the location of solid documentation for rails? For instance, where is the link_to method documented? The docs page at rubyforrails.com is overloaded with tutorials. I''ve read the tutorials, but unless they do EXACTLY what you want to do they aren''t much help. -Chris
Chris: What you are looking for is the :controller parameter. I think you want something like this: <%= link_to activity.name, :controller => ''activities'', :action => ''show'', :id => activity.id %> As for documentation, the new Agile Web Development with Ruby on Rails book is essential reading. I just got a copy for $25 shipped. Beyond that the Rails Wiki is always my second stop. Third, search the archives of this mailing list. Fourth, mail the list! -Jeff Chris wrote:>Alright, I''m a newbie so I''m not even sure if the subject of this post is >accurate, but here is what I want to do: > >The menu items that I want to show on every page of my site are stored in my >database. Each of them is an activity, so they are stored in the activities >database and I have them scaffolded to Activity. This all works great! > >The problem is in my layout I want to get all these activities and link to their >"show" action from the menu. Here is a snippet of code that I learned from >reading the tutorials: > ><% @activities = Activity.find_all %> ><% @activities.each do |activity| %> ><TR><TD> ><%= link_to activity.name, :action => "show", :id => activity.id %> ><% end %> > >Of course, if I''m looking at this from my home page, the links all point to: > >mysite.com/home/show/1 (for example) > >when I want them to point to > >mysite.com/activities/show/1 > >I''ve tried to replace "show" with Activity.show, but Rails says that the >Activity class doesn''t have a show method. I''ve even tried ../activities/show, >but that didn''t work either. > >Either I''m missing something really easy, or you''re not supposed to use ruby in >your layouts...I''m guessing it''s the former! > >Thanks for any help you can give. > >Also, just so I''m not here asking more stupid questions, can anyone enlighten me >to the location of solid documentation for rails? For instance, where is the >link_to method documented? The docs page at rubyforrails.com is overloaded with >tutorials. I''ve read the tutorials, but unless they do EXACTLY what you want to >do they aren''t much help. > >-Chris > >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > >
On Aug 21, 2005, at 8:56 AM, Chris wrote:> > Alright, I''m a newbie so I''m not even sure if the subject of this > post is > accurate, but here is what I want to do: > > The menu items that I want to show on every page of my site are > stored in my > database. Each of them is an activity, so they are stored in the > activities > database and I have them scaffolded to Activity. This all works great! > > The problem is in my layout I want to get all these activities and > link to their > "show" action from the menu. Here is a snippet of code that I > learned from > reading the tutorials: > > <% @activities = Activity.find_all %> > <% @activities.each do |activity| %> > <TR><TD> > <%= link_to activity.name, :action => "show", :id => activity.id %> > <% end %>Just add :controller => "activities" do the link_to call: <%= link_to activity.name, :controller => "activities", :action => "show", ... %> - Jamis> > Of course, if I''m looking at this from my home page, the links all > point to: > > mysite.com/home/show/1 (for example) > > when I want them to point to > > mysite.com/activities/show/1 > > I''ve tried to replace "show" with Activity.show, but Rails says > that the > Activity class doesn''t have a show method. I''ve even tried ../ > activities/show, > but that didn''t work either. > > Either I''m missing something really easy, or you''re not supposed to > use ruby in > your layouts...I''m guessing it''s the former! > > Thanks for any help you can give. > > Also, just so I''m not here asking more stupid questions, can anyone > enlighten me > to the location of solid documentation for rails? For instance, > where is the > link_to method documented? The docs page at rubyforrails.com is > overloaded with > tutorials. I''ve read the tutorials, but unless they do EXACTLY what > you want to > do they aren''t much help. > > -Chris > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
link_to(activity.name, { :controller => "activities", :action => "show", :id => activity.id } ) Also, don''t do the find in your view. Create a helper or something to load the activities in, by doing @activities = Activity.find(:all). On 8/21/05, Chris <getafade-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> > Alright, I''m a newbie so I''m not even sure if the subject of this post is > accurate, but here is what I want to do: > > The menu items that I want to show on every page of my site are stored in my > database. Each of them is an activity, so they are stored in the activities > database and I have them scaffolded to Activity. This all works great! > > The problem is in my layout I want to get all these activities and link to their > "show" action from the menu. Here is a snippet of code that I learned from > reading the tutorials: > > <% @activities = Activity.find_all %> > <% @activities.each do |activity| %> > <TR><TD> > <%= link_to activity.name, :action => "show", :id => activity.id %> > <% end %> > > Of course, if I''m looking at this from my home page, the links all point to: > > mysite.com/home/show/1 (for example) > > when I want them to point to > > mysite.com/activities/show/1 > > I''ve tried to replace "show" with Activity.show, but Rails says that the > Activity class doesn''t have a show method. I''ve even tried ../activities/show, > but that didn''t work either. > > Either I''m missing something really easy, or you''re not supposed to use ruby in > your layouts...I''m guessing it''s the former! > > Thanks for any help you can give. > > Also, just so I''m not here asking more stupid questions, can anyone enlighten me > to the location of solid documentation for rails? For instance, where is the > link_to method documented? The docs page at rubyforrails.com is overloaded with > tutorials. I''ve read the tutorials, but unless they do EXACTLY what you want to > do they aren''t much help. > > -Chris > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >