我对 Rails 还是很陌生,所以我可能会在这里错过一些非常重要的东西,这很容易修复,或者可能是我还没有研究过的部分。
我正在创建常规形式的巡回演出。该表单有很多字段,但有问题的字段是我的 collection_select。我要做的是在城市页面中显示与该城市相关的旅游。
这是我保存游览后出现的错误。
City(#70179438153960) expected, got String(#70179401165880)
模型/city.rb
class City < ActiveRecord::Base
has_many :cities
end
模型/tour.rb
class Tour < ActiveRecord::Base
belongs_to :user
belongs_to :city
end
我对城市和旅游有单独的控制器。虽然我确实将 :city 添加到 params.require(:tour).permit(.
意见/旅游/_form.html.erb
<%= simple_form_for(@tour) do |f| %>
<div class="inputs">
<%= f.input :company, label: "Company", input_html: { class: 'form-control' } %>
...
<%= collection_select :tour, :city, City.all, :id, :city, {:include_blank => true } %>
</div>
...
<% end %>
该表格完美地显示了所有城市,但是用城市更新游览给了我出现的错误。
作为稍后的额外问题,然后我想显示与该城市相关的所有旅行。例如访问 city/1 将显示该城市的游览。
谢谢!