1

別のモデルからコレクションを選択しようとしていますが、上記のエラーが引き続き発生します。どこでも見て、レールキャストを手に入れましたが、何も意味がありません。

_form.rb

 <%= f.label :city %><br />
 <%= f.collection_select (:share ,:city_id, City.all , :id, :name ) %>

エラーレポートで「フォーム」を強調表示します

<h1>New share</h1>
<%= render 'form' %>
<%= link_to 'Back', shares_path %>

これが私のモデルです...

class Share
  include Mongoid::Document
  field :name, type: String
  field :type, type: String
  field :summary, type: String
  field :description, type: String
  field :city, type: String

  embedded_in :city
  has_many :category
end

class City
  include Mongoid::Document

  embedded_in :share

  field :name, type: String
  field :country, type: String

  attr_accessible :name, :city_id, :id

end

あちこち探してもわからない。それはばかげたことに違いない。

4

1 に答える 1

4

The error is the whitespace after collection_select.

<%= f.collection_select(:city_id, City.all , :id, :name) %>

or

<%= f.collection_select :city_id, City.all , :id, :name %>

EDIT:

Taking into account that :share is your object, I have removed it (see above). The first param is the method:

collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
于 2013-11-01T19:41:13.167 に答える