0
我目前正在使用Rails 3.2应用程序,其中有两个控制器。一个是运动,另一个是帖子。他们都有一个before_filter。请看看控制器和路线如下:跳过之前筛选嵌套的资源
广告活动控制器:
class CampaignsController < ApplicationController
before_filter :authenticate_user!, except: [:show, :landing]
帖子控制器:
class PostsController < ApplicationController
before_filter :check_sign_in, :except => [:index]
路线:
resources :campaigns do
resources :posts
end
在Campaigns Controller中嵌套Posts控制器之前,Posts控制器中的before_filter工作正常,因为我不希望用户登录才能查看帖子。嵌套后,before_filter即使在通过Posts控制器中的:except块之后也不会检查用户。虽然我确实希望用户能够登录其他帖子操作。
:check_sign_in是在应用控制器,看起来像这样:
protected
def check_sign_in
redirect_to "#{sign_in_url}?origin=#{CGI::escape(request.fullpath)}" unless user_signed_in?
end
我已经试过许多东西要跳过帖子指数动作的before_filter但没有人似乎工作。我也尝试过skip_before_filter和skip_filter,但它们也不起作用。他们只是在所有帖子动作上跳过before_filter,如果我通过except块而不是执行before_filter,并且不要在索引操作上跳过它。
任何帮助解决这件事情,将不胜感激