简体   繁体   中英

Ruby on Rails error - NoMethodError in Statuses#new

I get this error NoMethodError in Statuses#new when I try to view a page in my app after I add the form field... I'm new to ruby on rails so am keen to be able to fully understand this...

<%= f.input :user_id %>

Here is the full error message:

NoMethodError in Statuses#new

Showing /Users/danlee/Projects/treebook/app/views/statuses/_form.html.erb where line #14 raised:

undefined method `user_id' for #<Status:0x007feb53cdd138>
Extracted source (around line #14):

11:     </div>
12:   <% end %>
13: 
14:   <%= f.input :user_id %>
15:   <%= f.input :content %>
16:   <div class="form-actions">
17:     <%= f.button :submit %>
Trace of template inclusion: app/views/statuses/new.html.erb

Rails.root: /Users/danlee/Projects/treebook

Application Trace | Framework Trace | Full Trace
app/views/statuses/_form.html.erb:14:in `block in _app_views_statuses__form_html_erb__4012047659275744874_70324335923840'
app/views/statuses/_form.html.erb:1:in `_app_views_statuses__form_html_erb__4012047659275744874_70324335923840'
app/views/statuses/new.html.erb:3:in `_app_views_statuses_new_html_erb___64465850179705865_70324349236340'
app/controllers/statuses_controller.rb:29:in `new'
Request

Parameters:

None
Show session dump

Show env dump

Response

Headers:

None

Github repository for the app is here too: https://github.com/pixeljugglerdan/treebook

It looks like you haven't added the :user_id column to your statuses. This file isn't running any code in the #change method: https://github.com/pixeljugglerdan/treebook/blob/master/db/migrate/20120911210237_add_user_id_to_statuses.rb

You'll probably want to re-run the migration with something like:

class AddUserIdToStatuses < ActiveRecord::Migration
  def change
    add_column :statuses, :user_id, :integer
  end
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM