How do I make before_filter run when using send method in Rails3?
My foo
controller is defined as such:
class FooController < ApplicationController
before_filter :authenticate, :only => :some_action
def show
send(some_action)
end
def some_action
end
private
def authenticate
# redirect user if not authenticated
end
end
Given I am not logged in, when I navigate directly to the some_action
action, I am redirected to the front page. When I navigate to the show action, however, I am not.
The before_filter doesn't run when 开发者_StackOverflowI call the action through the send
.
Right now, my workaround is to call authenticate
directly from my some_action
action.
Any ideas about why the before_filter doesn't get called through send
and how to fix it? Is this intended behavior for send
being called through a controller?
Thanks!
send
is a ruby metaprogramming method. You should only be using it in special circumstances, rather than all the time.
How about this?
class FooController < ApplicationController
before_filter :authenticate, :only => [:show, :some_action]
def show
...
end
def some_action
...
end
end
精彩评论