Sorry if this has been asked before; it seems like a simple problem. I have a controller called ItemController which displays information about specific items to a user on various pages. The routing looks like "items/:item/:action". Is there any way to automatically look up the :item in the items table (it''s just an ID). I tried: before_filter { @current_item = Item.find(:first, @params[:item], :include => [:set, :card]) } but apperently filters don''t have access to params. Is there any other simple way? Or is this somehow bad practice? -- 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 -~----------~----~----~----~------~----~------~--~---
Tom Potter wrote:> Sorry if this has been asked before; it seems like a simple problem. > > I have a controller called ItemController which displays information > about specific items to a user on various pages. The routing looks like > "items/:item/:action". Is there any way to automatically look up the > :item in the items table (it''s just an ID). > > I tried: > > before_filter { @current_item = Item.find(:first, @params[:item], > :include => [:set, :card]) } > > but apperently filters don''t have access to params. Is there any other > simple way? Or is this somehow bad practice?From the API docs: class WeblogController < ActionController::Base before_filter { |controller| false if controller.params["stop_action"] } end -- 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 -~----------~----~----~----~------~----~------~--~---
Tom Potter wrote:> Sorry if this has been asked before; it seems like a simple problem. > > I have a controller called ItemController which displays information > about specific items to a user on various pages. The routing looks like > "items/:item/:action". Is there any way to automatically look up the > :item in the items table (it''s just an ID). > > I tried: > > before_filter { @current_item = Item.find(:first, @params[:item], > :include => [:set, :card]) } > > but apperently filters don''t have access to params. Is there any other > simple way? Or is this somehow bad practice?alternatively before_filter :get_current_item def get_current_item @current_item = Item.find(:first, *blah*) 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 -~----------~----~----~----~------~----~------~--~---