Can anyone shed light on this for me?
undefined method `first_name’ for #
Here is the 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 %>
Here is the partial
<div class="comment">
<p>
<span class="commentator"><%= comment.commentator.display_name %>
say's</span>
<%= comment.comment %>
</p>
</div
Here is the friend view
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
This is the friends controller
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
I am trying to make it so a friend can leave a comment on an artists page but I keep getting the above error.
I am very new to Ruby so I apologise if I have left anything out.
Basically, rails will look at the database to figure out what fields are on a model. So make sure your migrations have been run, and that first_name exists on the db table.
Also, Friends is plural. In rails, your table is plural (friends), your model is singular (Friend), and your controller is plural (FriendsController). It is best not to go against this convention. Try renaming the model and see what happens