【发布时间】:2023-03-09 13:12:01
【问题描述】:
我们遇到了一个奇怪的问题。在应用程序控制器中,我们有一个before_filter 集,它需要使用devise 进行身份验证,并在需要时重定向到登录页面。
在我们的库控制器中,我们跳过了这个before_filter。
skip_before_filter :authenticate_user!, :only => :show
当我们使用 capybara 和 rspec 运行简单的功能测试时,测试失败。
it "should get only english articles within the category 'computers'" do
visit '/en/library/computers'
page.should have_content('computers')
end
看起来它没有跳过这个过滤器。页面内容为登录页面。
当我们使用rails server 运行它时,它运行良好。
任何想法为什么它会以这种方式运行或寻找什么来解决这个问题?
更新:
值得补充的是,这只发生在 Linux 上。在具有“相同”设置的 MacOS 10.7 下,它可以正常工作。
控制器代码:
class Library::CategoriesController < ApplicationController
skip_before_filter :authenticate_user!, :only => [:show]
# GET /categories/1
# GET /categories/1.json
def show
@categories = Category.all
@category = Category.find(params[:id])
@articles = @category.articles.where(:locale => I18n.locale)
respond_to do |format|
format.html # show.html.erb
end
end
end
application_controller 看起来像(没有 set_i18n_locale_from_url):
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :set_i18n_locale_from_url, :authenticate_user!
end
路线:
namespace :library do
get '/' => 'library#index', :as => 'library'
resources :categories, :path => '', :only => [:show]
resources :categories, :path => '', :only => [] do
resources :articles, :path => '', :only => [:show]
end
end
【问题讨论】:
-
我看到了完全相同的行为。
标签: ruby-on-rails-3 rspec devise capybara