Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.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 on rails I18n路由错误_Ruby On Rails_Ruby_Internationalization_Translation - Fatal编程技术网

Ruby on rails I18n路由错误

Ruby on rails I18n路由错误,ruby-on-rails,ruby,internationalization,translation,Ruby On Rails,Ruby,Internationalization,Translation,我正在通过I18n在我的应用程序中实现内部化 我已将路由更改为: root 'sessions#new' get '/signup', to: 'users#new' post '/signup', to: 'users#create' get '/login', to: 'sessions#new' post '/login', to: 'sessions#create' delete '/logout', to: 'sessions#destr

我正在通过I18n在我的应用程序中实现内部化

我已将路由更改为:

    root 'sessions#new'
    get '/signup', to: 'users#new'
    post '/signup', to: 'users#create'
    get '/login', to: 'sessions#new'
    post '/login', to: 'sessions#create'
    delete '/logout', to: 'sessions#destroy'
    resources :users, only: [:new, :show, :create, :index] 
致:

将显示的内容从www.example.com/users?locale=pl更改为www.example.com/pl/users

测试时

  test "should redirect show user when not logged in" do
    get user_path(@user)
    assert_not flash.empty?
    assert_redirected_to root_url
  end
我遇到了一个问题

错误:

UsersControllerTest#test(测试)在未登录时应(重定向)显示(用户):
> 
>ActionController::UrlGenerationError:没有路由匹配{:action=>“show”,:controller=>“users”,:locale=>#名字:“Jan”,姓氏:“Kowalski”,密码:“test12”,
>学生id:“123456”,创建于:“2016-12-16 21:02:17”,更新于:
>“2016-12-16 21:02:17”,曲奇文摘:无,管理员:真>}缺失
>所需密钥:[:id]
>test/controllers/users\u controller\u test.rb:16:in'block'

如何解决这个问题,同时保持url如下:example.com/pl/users?

在测试中调用
user\u path
时,您应该通过所需的
locale


与此类似,
user\u path(@user,locale::pl)

您也可以选中此选项,对于所有测试,必须有更好的选项将locale全局设置为当前的locale。
  test "should redirect show user when not logged in" do
    get user_path(@user)
    assert_not flash.empty?
    assert_redirected_to root_url
  end
UsersControllerTest#test_should_redirect_show_user_when_not_logged_in:
> 
>     ActionController::UrlGenerationError: No route matches {:action=>"show", :controller=>"users", :locale=>#<User id: 753762654,
> first_name: "Jan", last_name: "Kowalski", password: "test12",
> student_id: "123456", created_at: "2016-12-16 21:02:17", updated_at:
> "2016-12-16 21:02:17", cookies_digest: nil, admin: true>} missing
> required keys: [:id]
>     test/controllers/users_controller_test.rb:16:in `block<class:UsersControllerTest>'