"Common action" for a controller

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?

Tom Potter wrote:

: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 A.

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs