任何人都可以为我阐明这一点吗?
未定义的方法 `first_name' 用于#
这是show.html
<p id="notice"><%= notice %></p>
<div id="container">
<p>
<b>First name:</b>
<%= @artist.firstname %>
</p>
<p>
<b>Second name:</b>
<%= @artist.surname %>
</p>
<p>
<b>About:</b>
<%= @artist.about %>
</p>
<div id="comments">
<h2>Comments</h2>
<%= render :partial => "shared/comment", :collection => @artist.comments%>
</div
</div>
<%= render :partial => "image", :collection => @artist.images %>
<%= link_to 'Edit', edit_artist_path(@artist) %> |
<%= link_to 'Back', artists_path %>
<%= link_to 'show', images_path %>
这是部分
<div class="comment">
<p>
<span class="commentator"><%= comment.commentator.display_name %>
say's</span>
<%= comment.comment %>
</p>
</div
这是朋友的看法
class Friends < ActiveRecord::Base
attr_accessible :firstname, :surname
has_many :comments, :as => :commentator, :class_name =>"Commentable"
def display_name
"#{self.firstname} #{self.surname}"
end
end
这是朋友控制器
class FriendsController < ApplicationController
# GET /friends
# GET /friends.xml
def index
@friends = Friend.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @friends }
end
end
# GET /friends/1
# GET /friends/1.xml
def show
@friend = Friend.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @friend }
end
end
# GET /friends/new
# GET /friends/new.xml
def new
@friend = Friend.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @friend }
end
end
# GET /friends/1/edit
def edit
@friend = Friend.find(params[:id])
end
# POST /friends
# POST /friends.xml
def create
@friend = Friend.new(params[:friend])
respond_to do |format|
if @friend.save
format.html { redirect_to(@friend, :notice => 'Friend was successfully created.') }
format.xml { render :xml => @friend, :status => :created, :location => @friend }
else
format.html { render :action => "new" }
format.xml { render :xml => @friend.errors, :status => :unprocessable_entity }
end
end
end
# PUT /friends/1
# PUT /friends/1.xml
def update
@friend = Friend.find(params[:id])
respond_to do |format|
if @friend.update_attributes(params[:friend])
format.html { redirect_to(@friend, :notice => 'Friend was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @friend.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /friends/1
# DELETE /friends/1.xml
def destroy
@friend = Friend.find(params[:id])
@friend.destroy
respond_to do |format|
format.html { redirect_to(friends_url) }
format.xml { head :ok }
end
end
end
我正在努力让朋友可以在艺术家页面上发表评论,但我不断收到上述错误。
我对 Ruby 很陌生,所以如果我遗漏了任何内容,我深表歉意。