I recently dived into Rails and am having trouble with the link_to method. I''d like to pass some parameters to the action being called and am not sure how to do it. Essentially, I want to hyperlink a total count of bugs queried from the database to a method that will return the bug numbers when clicked on. I have a method, bug_total, that returns the total number to display in the view. I have another method, total_bugs, that will return the bugzilla url with all the bugid''s for that particular build when clicked. Below is what I have in my view. I''d like to pass the :action=>"total_bugs" some parameters(build_number, developer_name, product_name) based on the current build. I''ve tried many ways and haven''t been successfull, yet. Any help is greatly appreciated. Thanks! <% for build in @bugDashboard %> <span class="tabledata"> <%= link_to build.bug_total, {:controller => "dashboard", :action => "total_bugs"} %> </span> ..... -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060328/f73cef6b/attachment.html
> <% > for build in @bugDashboard > %> > <span class="tabledata"> > <%= link_to build.bug_total, {:controller => "dashboard", > :action => "total_bugs"} %> > </span> > > .....<%= link_to (build.bug_total), :controller ....... %> that should work... -- Posted via http://www.ruby-forum.com/.
Francois Beausoleil
2006-Mar-28 21:57 UTC
[Rails] Brand newbie question relating to link_to
2006/3/27, David Sliwa <dsliwa@gmail.com>:> <% > for build in @bugDashboard > %> > <span class="tabledata"> > <%= link_to build.bug_total, {:controller => "dashboard", > :action => > "total_bugs"} %> > </span>Hmm, have you tried this ? build_number, developer_name, product_name <%= link_to build.bug_total, :controller => "dashboard", :action => "total_bugs", :build_number => ''123'', :developer_name => ''francois'', :product_name => ''rails'' %> #link_to automatically makes any leftover parameters query parameters: <a href="/dashboard/total_bugs?build_number=123&developer_name=francois&product_name=rails">1</a> In the action, you can access the parameters using the params Hash: def total_bugs params[:product_name] # => "rails" params[:build_number] # => "123" params[:developer_name] # => "francois" end NOTE: All parameters are strings in the params Hash. When you are ready to explore routes, you can build a URL like this instead: /dashboard/total_bugs/rails/francois/123 map.connect ''/dashboard/total_bugs/:product_name/:developer_name/:build_number'', :controller => "dashboard", :action => "total_bugs" which would give you the exact same params Hash as above. Hope that helps ! -- Fran?ois Beausoleil http://blog.teksol.info/
Thank you Francois! That worked great. I haven''t tried the route way, yet, but will when I get this thing up and running. You help is greatly appreciated! On 3/27/06, Francois Beausoleil <francois.beausoleil@gmail.com> wrote:> > 2006/3/27, David Sliwa <dsliwa@gmail.com>: > > <% > > for build in @bugDashboard > > %> > > <span class="tabledata"> > > <%= link_to build.bug_total, {:controller => "dashboard", > > :action => > > "total_bugs"} %> > > </span> > > Hmm, have you tried this ? > > build_number, developer_name, product_name > <%= link_to build.bug_total, :controller => "dashboard", :action => > "total_bugs", :build_number => ''123'', :developer_name => ''francois'', > :product_name => ''rails'' %> > > #link_to automatically makes any leftover parameters query parameters: > > <a > href="/dashboard/total_bugs?build_number=123&developer_name=francois&product_name=rails">1</a> > > In the action, you can access the parameters using the params Hash: > > def total_bugs > params[:product_name] # => "rails" > params[:build_number] # => "123" > params[:developer_name] # => "francois" > end > > NOTE: All parameters are strings in the params Hash. > > When you are ready to explore routes, you can build a URL like this > instead: > > /dashboard/total_bugs/rails/francois/123 > > map.connect''/dashboard/total_bugs/:product_name/:developer_name/:build_number'', > :controller => "dashboard", :action => "total_bugs" > > which would give you the exact same params Hash as above. > > Hope that helps ! > -- > Fran?ois Beausoleil > http://blog.teksol.info/ > > _______________________________________________ > 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/20060329/c620b139/attachment.html