用于编辑用户设置的自定义视图 |未定义的方法`user_path'

问题描述

使用 devise gem,我希望能够编辑用户设置,而无需用户每次都输入密码,特别是考虑到他们通过 omniauth 注册后不知道自己的密码。

按照创作者的建议,我创建了一个单独的控制器:

class SettingsController < ApplicationController
  def edit
    @user = current_user
  end
end

添加了一条路线...

get 'settings',to: 'settings#edit',as: 'user_settings'

...并创建了一个视图:

<h1>Settings</h1>


<%= simple_form_for(@user) do |f| %>
  <%= f.input :email %>
  <%= f.input :name %>
  ...
  <div class="form-actions">
    <%= f.button :submit,"Update" %>
  </div>
<% end %>

<h3>Cancel my account</h3>

<p>Unhappy? <%= link_to "Cancel my account",registration_path(resource_name),data: { confirm: "Are you sure?" },method: :delete %></p>

<%= link_to "Back",:back %>

不幸的是,这仅仅导致了以下错误

NoMethodError in Settings#edit
undefined method `user_path' for #<#<Class:0x00007fcf53c00290>:0x00007fcf53c0a790>

Extracted source (around line #4):
<%= simple_form_for(@user) do |f| %>
  <%= f.input :email %>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)