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