Ruby on rails 向用户展示设计

Ruby on rails 向用户展示设计,ruby-on-rails,devise,Ruby On Rails,Devise,我正在尝试为我的每个用户创建一个显示页面作为配置文件页面。然而,每当我试图在视图中显示任何内容时,我总是将nil:NilClass的未定义方法“username”作为错误消息 我正在使用Desive注册和存储用户信息。我的用户被称为艺术家 /routes.rb devise_for :artists, controllers: { sessions: "artists/sessions", passwords: "artists/passwords", registrations: "arti

我正在尝试为我的每个用户创建一个显示页面作为配置文件页面。然而,每当我试图在视图中显示任何内容时,我总是将nil:NilClass的未定义方法“username”作为错误消息

我正在使用Desive注册和存储用户信息。我的用户被称为艺术家

/routes.rb

devise_for :artists, controllers: { sessions: "artists/sessions", passwords: "artists/passwords", registrations: "artists/registrations", confirmations: "artists/confirmations",  unlocks: "artists/unlocks"}
resources :artists, only: [:show, :index]

/artists_controller.rb

class ArtistsController < ApplicationController
 def show
  @artist = Artist.find(params[:id])
 end
end

/show.html.erb

<%= @artist.username %>
如果我试图显示电子邮件、ID等,就会出现此错误

日志

如果要将ArtistsController嵌套到/artists中,则需要使用

get 'artists/:id' => 'artists/artists#show', as: :artist


这里肯定发生了其他事情,因为ActiveRecord::Basefind永远不会返回nil。如果找不到记录,它将引发错误。你的日志怎么说请求参数?奇怪。你能在控制器中的artist.find调用之后添加一个p@artist吗?另外,您是否已停止并重新启动服务器?我很确定这不会发生在你描述的设置中。好吧,因此,我所做的是将艺术家视图显示放在艺术家文件夹views/artists/artists/show.html.erb中,将控制器放在controller/artists/artists\u controller.rb中,并将类更改为artists::artists controller'artists/artistsshow',如果我手动输入,效果很好,但是如果我尝试链接到当前艺术家,我会得到一个错误未定义的方法'Artister\u path'。查看rake路线,没有艺术家/艺术家的路径名show
get 'artists/:id' => 'artists/artists#show', as: :artist
resources :artists, controller: 'artists/artists', only: [:show]