简体   繁体   English

语法错误,意外',',期待')'RoR

[英]syntax error, unexpected ',', expecting ')' RoR

I am trying to get a collection select from an another model and I keep getting the above error. 我试图从另一个模型中选择一个集合,我不断收到上述错误。 Looked everywhere, got rails casts but nothing makes sense. 无处不在,看到了铁轨,但没有任何意义。

_form.rb _form.rb

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

It highlights 'form' on the error report 它突出显示错误报告中的“表单”

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

Here are my models... 这是我的模特......

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

Searched everywhere and I cannot figure it out. 到处搜索,我无法弄清楚。 It must be something silly. 一定是傻事。

The error is the whitespace after collection_select . 错误是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). 考虑到:share是你的对象,我已将其删除(见上文)。 The first param is the method: 第一个参数是方法:

collection_select(method, collection, value_method, text_method, options = {}, html_options = {})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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