Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 控制器规范中的重定向预期失败_Ruby_Ruby On Rails 3_Devise - Fatal编程技术网

Ruby 控制器规范中的重定向预期失败

Ruby 控制器规范中的重定向预期失败,ruby,ruby-on-rails-3,devise,Ruby,Ruby On Rails 3,Devise,我使用的是Desive 1.4.2、RSpec 2.6.0和Rails 3.1.0.rc6。我的routes.rb如下所示: scope "(:locale)", :locale => /e(s|n)/ do resources :demotivideos, :only => [:index, :show] devise_for :users namespace "admin" do resources :demotivideos, :except =>

我使用的是Desive 1.4.2、RSpec 2.6.0和Rails 3.1.0.rc6。我的
routes.rb
如下所示:

scope "(:locale)", :locale => /e(s|n)/ do
  resources :demotivideos, :only => [:index, :show]
  devise_for :users

  namespace "admin" do
    resources :demotivideos, :except => [:index, :show]
  end
end
我规定,当一个未登录的用户访问新建、创建或更新时,他应该被重定向到
new\u user\u session\u path
。为此,我使用以下代码

context "when not logged in" do
  before(:each) do
    sign_out user
  end

  describe "GET new" do

    it "should redirect to new user session" do
      get :new
      response.should redirect_to(new_user_session_path)
    end
  end

  describe "POST create" do

    it "should redirect to new user session" do
      post :create, :demotivideo => valid_attributes
      response.should redirect_to(new_user_session_path)
    end
  end

  describe "PUT update" do

    it "should redirect to new user session" do
      put :update, :id => 1, :demotivideo => valid_attributes
      response.should redirect_to(new_user_session_path)
    end
  end
end
由于相同的原因,所有路由都失败:预期路由包括区域设置(默认为en),但实际重定向到没有区域设置的相同路径。我的应用程序控制器已按照中的说明进行了修改:

class ApplicationControllerI18n.locale}
结束
def set_语言环境
I18n.locale=params[:locale]| | I18n.default_locale
结束
结束
我做错了什么?

似乎在您需要的
def self.default\u url\u选项中使用了
def default\u url\u选项。但我不知道有什么区别

class ApplicationController < ActionController::Base
  protect_from_forgery

  before_filter :set_locale

  def default_url_options(options={})
    logger.debug "default_url_options is passed options: #{options.inspect}\n"
    { :locale => I18n.locale }
  end

  def set_locale
    I18n.locale = params[:locale] || I18n.default_locale
  end
end