0

I followed this page step-by-step Micropost's comments on users page (Ruby on Rails)

then I looked into my error that I'm getting here form_for , undefined method name

I ran "rails generate migration add_comment_content_to_micropost comment_content:text" then ran "rake db:migrate"

However, I'm still getting the undefined method `comment_content'error

NoMethodError in Users#show

Showing C:/app/views/shared/_comment_form.html.erb where line #4 raised:

undefined method `comment_content' for #<Comment:0x4fe56b8>

Here's the section where the column is from schema.db

create_table "microposts", :force => true do |t|
    t.string   "content"
    t.integer  "user_id"
    t.datetime "created_at",      :null => false
    t.datetime "updated_at",      :null => false
    t.text     "commentcontent"
    t.text     "comment_content"
  end
Community
  • 1
  • 1
Amy Brown
  • 117
  • 2
  • 9

2 Answers2

1

The error is referring to a Comment object, not a Micropost object. In your show method you need to refer to the correct object.

Looking at the post you refer to you've made a few mistakes. For example the Comment class should have the comment_content field, not the Micropost.

I don't think you've created the models correctly. For example your Comment model should have a user_id and a micropost_id to satisfy the belongs_to :user and belongs_to :micropost relationships.

Richard Brown
  • 11,346
  • 4
  • 32
  • 43
  • do you mind showing me how to refer to the correct object? I followe this step-by-step here http://stackoverflow.com/questions/9669221/microposts-comments-on-users-page-ruby-on-rails – Amy Brown Mar 10 '13 at 07:02
  • That question leaves some information out, assuming you know how to do migrations for the relationships between `Comment`, `Micropost`, and `User`. I edited my answer for an example. – Richard Brown Mar 10 '13 at 07:06
  • I was able to work through most of the issue but now I'm getting the word "Asset" displayed right above the commenting box. Do you know why that occurs? I couldn't find any relevant searches on this error where the text "Asset" is showing up – Amy Brown Mar 10 '13 at 07:51
0

It's looks like you have set associations in your model wrongly. Please visit here to know the way to make associations.

http://guides.rubyonrails.org/association_basics.html

Ramiz Raja
  • 5,942
  • 3
  • 27
  • 39