0
"Store"라는 모델이 있고 "City"와 연결된 "State"속성이 있습니다. simple_form을 사용하여 주 및/또는시에서 상점의 필터를 만듭니다. 문제는 simple_form을 "State"를 "Store"에 연결하지 않는 방법입니다.모델에 연관성없이 선택을 추가하는 방법은 무엇입니까?
class State < ActiveRecord::Base
attr_accessible :name
has_many :cities
end
class City < ActiveRecord::Base
attr_accessible :name
belongs_to :state
has_many :stores
end
class Store < ActiveRecord::Base
attr_accessible :latitude, :longitude, :description, :city_id
validates :city, :presence => true
validates :description, :presence => true, :length => {:maximum => 500}
validates :latitude, :presence => true
validates :longitude, :presence => true
belongs_to :city
end
<%= simple_form_for @store, :html => { :class => 'add-store-form', :style => "display:none;" } do |f| %>
<table border="0">
<tr>
<td>Estado:</td>
<td>
<%= f.collection_select :state, State.all, :include_blank => false, :label => false,
:input_html => { :id => "state_id", :name => "state_id" } %>
</td>
</tr>
.
.
이 방법은 작동하지 않습니다. 어떻게해야합니까?
미리 감사드립니다.
validates :city, :latitude, :longitude, :description, presence: true
validates :description, length: {maximum: 500}
을 내가 속성 대신 attr_accessible 옵션
니스 팁의 형태에서 할당 할 수 있습니다로 정의 할
Strong Parameters (Default in rails 4)
을 사용하는 것이 좋습니다 : 당신은 질문,하지만 수행하여 코드를 개선하기 위해 – hugalves확인 된 답변을 사용하여 해결 : http://stackoverflow.com/questions/11349508/rails-simpleform-with-non-model-inputs – hugalves