0
我是非常新的導軌開發。 我正在爲我的投資組合網站創建一個簡單的後端。2個型號在導軌3中的形式
我不確定這個問題的標題。我之前提出的一個問題可能過於複雜。所以我正在簡化它。
進出口使用3種型號:郵政,附件,Attachment_Category
我有我使用的一種形式:
草案後有標題,內容和類別。
顯示附件的類別在下拉(幻燈片,圖像,視頻)
上傳附件(多個)。
我已經實現步驟1和2
第3步:我希望它這樣,當我終於打提交表單時,attachment_category_id保存到附件表。
我有以下關係:
Post.rb
class Post < ActiveRecord::Base
has_many :attachment_categories, :through => :attachments
has_many :attachments,:dependent => :destroy
accepts_nested_attributes_for :attachments
validates_presence_of :title, :content, :category
end
Attachment.rb
class Attachment < ActiveRecord::Base
belongs_to :post
belongs_to :attachment_category
#paperclip
has_attached_file :photo, :styles =>{
:thumb => "100x100#",
:small => "400x400>"
}
end
Attachment_category.rb
class AttachmentCategory < ActiveRecord::Base
has_many :posts , :through => :attachments
has_many :attachments
validates :category_name, :presence =>true
end