0

添加表单字段后,当我尝试在我的应用程序中查看页面时,我在 Statuses#new 中收到此错误NoMethodError ...我是 ruby​​ on rails 的新手,所以很想能够完全理解这一点...

<%= f.input :user_id %>

这是完整的错误消息:

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 存储库也在这里:https ://github.com/pixeljugglerdan/treebook

4

1 回答 1

3

看起来您尚未将 :user_id 列添加到您的状态中。此文件未在 #change 方法中运行任何代码:https ://github.com/pixeljugglerdan/treebook/blob/master/db/migrate/20120911210237_add_user_id_to_statuses.rb

您可能希望使用以下内容重新运行迁移:

class AddUserIdToStatuses < ActiveRecord::Migration
  def change
    add_column :statuses, :user_id, :integer
  end
end
于 2012-09-22T22:23:00.573 回答