안녕하세요, 저는 하나의 형식으로 다른 모델에서 두 개의 개체를 만들려고합니다. 이들은 has_many/belongs_to 관계로 연결됩니다. 다른 모델과 연관 될 수 있기 때문에 이벤트는 다형성을 가진 has_many 그림입니다. 내가 받고있어 보호 된 속성을 대량 할당 할 수 없다 : 설정 한 그림 : attr_accesible의 그림은 "unknown attribute : picture"이다.하나의 양식에 두 개의 모델을 만드는 레일
<%= form_for @event, :html => { :class => 'form-horizontal' } do |f| %>
<div class="control-group">
<%= f.label :titre, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :titre, :class => 'text_field' %>
</div>
</div>
<div class="control-group">
<%= f.label :Date, :class => 'control-label' %>
<div class="controls">
<%= f.date_select :dday, :class => 'date_select', :start_year=>Date.today.year, :end_year=>1905 %>
</div>
</div>
<div class="control-group">
<%= f.label :lieux, :class => 'control-label' %>
<div class="controls">
<%= f.text_field :lieux, :class => 'text_field' %>
</div>
</div>
<div class="control-group">
<%= f.label :description, :class => 'control-label' %>
<div class="controls">
<%= f.text_area :commentaire, :class => 'text_area', :rows => 4 %>
</div>
</div>
<%= f.fields_for @event.pictures.new do |p| %>
<%= p.text_field :name, :placeholder=>"Nom de votre image" %>
<%= p.file_field :image %>
<% end %>
내 모델 코드를 도와
class Event < ActiveRecord::Base
attr_accessible :dday, :lieux, :titre, :commentaire, :picture
belongs_to :user
has_many :pictures, :as => :imegeable ,:dependent => :destroy
default_scope :order => :dday
validates :dday, :titre, :presence=>true
end
감사 :
여기 내 양식 코드입니다.
내가 그것을하고있다. 나는 새로운 오류를 얻는다. "이름'그림 '에 대한 연관이 없습니다. 아직 정의 되었습니까?" – user1796260
'picture'가 아닌 'pictures'가 수정되었습니다. – ChrisC
죄송합니다 무슨 말씀인지 모르겠습니까? – user1796260