简体   繁体   English

设计路由问题

[英]Devise routing issue

I am getting a really frustrating error and I think it is a simple fix. 我遇到了一个非常令人沮丧的错误,我认为这是一个简单的修复。 In my header, when I try to include a link called "My Account" that routes to the user's profile, I get: 在标题中,当我尝试包含一个链接到用户个人资料的名为“我的帐户”的链接时,我得到:

No route matches {:action=>"show", :controller=>"users"}

Everything else works in terms of signup/in with devise, and I can get to the user profile page after signing in at localhost:3000/users/1 其他一切都可以通过devise进行注册/登录,在localhost:3000 / users / 1登录后,我可以进入用户个人资料页面

My link code in the view: 我在视图中的链接代码:

<%= link_to "My Account", user_path %>

Also, I get the exact same error when trying to route to the edit user profile page at "edit_user_registration_path": 另外,当尝试路由到“ edit_user_registration_path”处的编辑用户配置文件页面时,也会收到完全相同的错误:

<%= link_to "Edit Profile", edit_user_registration_path, class: "prof-btn" %>

I also tried: 我也尝试过:

<%= link_to "Edit Profile", edit_user_registration_path(@user), class: "prof-btn" %>

But same error. 但是同样的错误。

My routes.rb file: 我的routes.rb文件:

root to: 'static_pages#home' ActiveAdmin.routes(self) devise_for :admin_users, ActiveAdmin::Devise.config devise_for :users resources :users 根目录到:'static_pages#home'ActiveAdmin.routes(self)devise_for:admin_users,ActiveAdmin :: Devise.config devise_for:users资源:users

My users_controller.rb: 我的users_controller.rb:

class UsersController < ApplicationController 类UsersController <ApplicationController

def show
    @user = User.find(params[:id])
end

def create
    @user = User.create(params[:user])
end

def edit
    @user = User.find(params[:id])
end

在此处输入图片说明

Any help on this would be appreciated! 任何帮助,将不胜感激!

您必须将用户传递给路径助手。

<%= link_to "My Account", user_path(current_user) %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM