I am currently working on a Rails 3.2 application in which I have two controllers. One is campaign and the other one is posts. Both of them are having a before_filter. Please have a look at the controller and routes below :
Campaigns Controller :
class CampaignsController < ApplicationController
before_filter :authenticate_user!, except: [:show, :landing]
Posts Controller:
class PostsController < ApplicationController
before_filter :check_sign_in, :except => [:index]
Routes :
resources :campaigns do
resources :posts
end
Before nesting the Posts Controller in Campaigns Controller the before_filter in Posts controller was working fine as I do not want the user to be logged in to just view the post. After nesting the before_filter is getting rendered even after passing the :except block in Posts controller not to check for user. Though I do want the user to be logged in for rest of the Posts action's.
:check_sign_in is in application controller and looks like this :
protected
def check_sign_in
redirect_to "#{sign_in_url}?origin=#{CGI::escape(request.fullpath)}" unless user_signed_in?
end
I have tried multiple things to skip the before_filter on Posts Index action but none of them seems to work. I have also tried skip_before_filter and also skip_filter but they are also not working. They simply skip before_filter on all the posts action and if I pass the except block than it implements the before_filter and do not skip it on index action.
Any help to solve this thing would be appreciated
The problem was not solved so I ended up doing it the other way !