【发布时间】:2013-08-20 17:07:45
【问题描述】:
这似乎是我(可能在概念上)再次出现的问题,希望这次我能解决它! #stillLearning
两种型号。 一个集合 has_many :examples 一个例子 belongs_to :collection
集合有一个标题:字符串 示例有collection_id:整数和描述:文本
在我的收藏/展示中,我还希望能够通过这个简单的表单添加一个示例:
<%= form_for(@example) do |e| %>
<h3><%= e.label :description %></h3>
<%= e.text_area :description %>
<%= e.submit %>
<% end %>
但是我得到一个 NoMethodError...
undefined method `description' for #<Collection:0x007fe3c4087898>.
我知道@collection 没有 :description,所以这意味着我必须在 Collection 和 Example 之间创建一个链接,对吗?
假设我的猜测是正确的,我尝试了:
rails g migration AddExampleRefToCollections example:references
但出现以下错误:
SQLite3::SQLException: near "references": syntax error: ALTER TABLE "collections" ADD "example" references/Users/davidngo/.rvm/gems/ruby-1.9.3-p429/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:in `initialize'
【问题讨论】:
-
感谢您修复我帖子的格式。还在学习正确的礼仪!
标签: ruby-on-rails rails-migrations rails-models