所以在拉了我的头发一个小时后,我决定在这里发布这个。我收到此错误:
NoMethodError in Articles#show
Showing /home/leon/sites/VIS/app/views/articles/_article.html.erb where line #3 raised:
undefined method `user_path' for #<#<Class:0x7fdd81fe1eb8>:0x7fdd81fdfdc0>
Extracted source (around line #3):
1: <div id="left-column">
2: <p class="label-b">Author<br>
3: <%= link_to "#{@article.user.penname}'s profile", user_path(article.user) %>
user_path(article.user) %>
当我尝试链接到文章的创作用户时。我的路线文件:
resources :tags
get "admin/index"
get "admin/show"
get "articles/contact"
get "articles/about"
resources :roles
devise_for :users, :controllers => { :registrations => "users/registrations" }
resources :articles do
resources :comments
end
我的文章模型文件中有一个 belongs_to :user ,我的用户模型文件中有一个 has_many :articles 。我正在使用此链接链接到文章中作者的个人资料。
请帮忙!我正在使用 can can 进行权限管理并设计用于身份验证,但是它在文章的显示操作中引发了错误,因此我没有发布该代码。让我知道我是否应该这样做。谢谢!
@雅各布
我犯了同样的错误:
文章中的 NoMethodError#show
显示 /home/leon/sites/VIS/app/views/articles/_article.html.erb 其中第 3 行提出:
#<#:0x7fdd82217a98> 的未定义方法 `user_path' 提取的源代码(在第 3 行附近):
1: 2: 作者
3: <%= link_to "#{@article.user.penname}'s profile", article.user %> 4: 以前的版本 5: 版本 7
我的路线的相关部分:
{:action=>"destroy", :controller=>"roles"}
new_user_session GET /users/sign_in(.:format) {:action=>"new", :controller=>"devise/sessions"}
user_session POST /users/sign_in(.:format) {:action=>"create", :controller=>"devise/sessions"}
destroy_user_session GET /users/sign_out(.:format) {:action=>"destroy", :controller=>"devise/sessions"}
user_password POST /users/password(.:format) {:action=>"create", :controller=>"devise/passwords"}
new_user_password GET /users/password/new(.:format) {:action=>"new", :controller=>"devise/passwords"}
edit_user_password GET /users/password/edit(.:format) {:action=>"edit", :controller=>"devise/passwords"}
user_password PUT /users/password(.:format) {:action=>"update", :controller=>"devise/passwords"}
user_registration POST /users(.:format) {:action=>"create", :controller=>"users/registrations"}
new_user_registration GET /users/sign_up(.:format) {:action=>"new", :controller=>"users/registrations"}
edit_user_registration GET /users/edit(.:format) {:action=>"edit", :controller=>"users/registrations"}
user_registration PUT /users(.:format) {:action=>"update", :controller=>"users/registrations"}
user_registration DELETE /users(.:format) {:action=>"destroy", :controller=>"users/registrations"}
user_confirmation POST /users/confirmation(.:format) {:action=>"create", :controller=>"devise/confirmations"}
new_user_confirmation GET /users/confirmation/new(.:format) {:action=>"new", :controller=>"devise/confirmations"}
user_confirmation GET /users/confirmation(.:format) {:action=>"show", :controller=>"devise/confirmations"}
啊哈!它没有用户#show的路线,但我不知道为什么,因为我有:
class UsersController < ApplicationController
...
def show
respond_to do |format|
format.json { render :json => @user }
format.xml { render :xml => @user }
format.html
end
rescue ActiveRecord::RecordNotFound
respond_to_not_found(:json, :xml, :html)
end
在我的应用程序/控制器文件夹中。我是否需要将我的用户控制器移动到 app/controllers/devise 并用设计而不是应用程序控制器重载它?