【问题标题】:How to use custom view to update user via devise? (rails gem)如何使用自定义视图通过设计更新用户? (导轨宝石)
【发布时间】:2016-05-31 01:42:29
【问题描述】:

我为设计构建了 2 个自定义视图,1 个更改密码,另一个更新其他自定义信息。密码更新成功了,所以我复制了第二个视图的方法,但是在提交数据时出现错误

No route matches [PATCH] "/users/discovery_settings/update"

这没有意义,因为我的路线是

 devise_for :users, controllers: {registrations: 'users/registrations'}
 as :user do 

end    
get 'users/discovery_settings' => 'users#discovery_settings'
post 'users/discovery_settings/update' => 'users#update_discovery'

在我的控制器中,我使用与密码更新相同的方法

  def update_discovery
     @user = User.find(current_user.id)
     if @user.update(user_params)
       # Sign in the user by passing validation in case their password changed
       sign_in @user, :bypass => true
       redirect_to root_path
     else
       render "edit"
     end
  end

然后我在我的 form_for 视图中调用它

 <%= form_for(@user, :url => { :action => "update_discovery" }, html: {class: "form floating-label"})  do |f| %>

任何想法如何解决路由错误? 当我已经指定“帖子”时,我不知道为什么它正在寻找“补丁”

【问题讨论】:

  • 我的忍者设计大师在哪里?

标签: ruby-on-rails devise routes


【解决方案1】:

错误告诉你。您有一个 POST 路由,并且更新要求一个 PATCH 路由。

尝试使用 patch 而不是 post

patch 'users/discovery_settings/update' => 'users#update_discovery'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-08
    • 2012-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多