【问题标题】:Cannot get to edit view to modify profile无法编辑视图以修改配置文件
【发布时间】:2016-05-08 10:11:35
【问题描述】:

尝试编辑用户个人资料:

在_footer (link_to "Edit profile", edit_user_path):

<% if current_user %>
    <% if admin? %>
      <%= link_to "Admin Page", admin_users_path %> Signed in as <%= current_user.username %> <%= link_to "Edit profile", edit_user_path %>(<%= link_to "Log out", session_path("current"), method: :delete %>) etc

在用户控制器中:

 def edit
    @user = current_user
    end

在用户编辑视图中:

    <%= form_for @user do |f| %>
      <% if @user.errors.any? %>
etc

路线:

resources :users, only: [:new, :create, :edit]

我显然遗漏了一些关键概念,完全指向另一个控制器:ActionController::UrlGenerationError in Movies#index,

没有路由匹配 {:action=>"edit", :controller=>"users"} 缺少必需的键:[:id]

只是想知道这是怎么回事,谢谢!

【问题讨论】:

  • 找到了一个很好的教程。

标签: ruby-on-rails path


【解决方案1】:

上面提到了您的错误。没有路由匹配 {:action=>"edit", :controller=>"users"} 缺少必需的键:[:id] 您必须将用户 ID 传递给它。

<%= link_to "Edit profile", edit_user_path(current_user) %>

【讨论】:

  • 感谢两位!睡了一会儿,我意识到我也应该打开用户资源。
【解决方案2】:

Movies#index 中的 ActionController::UrlGenerationError,

没有路由匹配 {:action=>"edit", :controller=>"users"} 缺失 所需键:[:id]

edit_user_path 需要 :id 作为密钥,因此您需要传递它。以下应该可以工作

<%= link_to "Edit profile", edit_user_path(current_user) %>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-15
    • 2018-07-03
    • 2016-11-24
    • 2015-10-01
    • 2016-08-17
    • 1970-01-01
    • 1970-01-01
    • 2011-01-20
    相关资源
    最近更新 更多