如何解决Devise Registrations控制器中的参数错误?

时间:2017-01-13 10:22:32

标签: ruby-on-rails devise

我使用设计设计令牌身份验证宝石。我想输入编辑用户路径

<%= link_to "Edit profile", edit_user_registration_path(current_user.id) %>

但得到了一个错误 这部分代码 def authenticate_user! def authenticate_user! if user_signed_in? super else redirect_to new_user_session_path end end

我的路线

Rails.application.routes.draw do
  devise_for :users
  get 'demo/members_only', to: 'payments#members_only'
  # token auth routes available at /api/v1/auth
  namespace :api do
    scope :v1 do
      mount_devise_token_auth_for 'User', at: 'auth'
    end
  end
  resources :payments
  root "payments#index"
end

现在想法如何解决它。

3 个答案:

答案 0 :(得分:1)

看起来像devise_token_auth重新定义了基本的设计助手,这就是它无效的原因。

答案 1 :(得分:0)

您不需要传递当前用户的id,设计会从会话中获取当前用户对象,只需这样做就可以了。您好了。

<%= link_to "Edit profile", edit_user_registration_path %>

希望有所帮助!

答案 2 :(得分:0)

如果使用current_user,则无需单独传递。{p>如果没有提供参数,Devise将使用它。

<%= link_to "Edit profile", edit_user_registration_path %>

如果您传递用户记录,而不是id

,也应该起作用
<%= link_to "Edit profile", edit_user_registration_path(current_user) %>