samedi 23 janvier 2016

rails nasted model form

I have model association like this

post.rb

title:string description:text

class Post < ActiveRecord::Base

    belongs_to :user
    has_many :items
    accepts_nested_attributes_for :items

end

item.rb

post_id:integer order:integer

class Item < ActiveRecord::Base
  belongs_to :post
  has_one :link
  has_one :movie
  has_one :photo
  has_one :quate
end

link, movie, photo, quate.rb

link.rb : item_id:integer url:string url-text:string

movie.rb : item_id:integer youtube-url:string

photo.rb : item_id:integer image:string comment:string title:string

quate.rb : item_id:integer quate:string q-url:string q-title:string

  belongs_to :item

I want to build user-post application by ruby on rails. Item model has order column ,so user can choose and add whatever movie, link , photo to build there own post.

How can I build form for these nasted models?

Aucun commentaire:

Enregistrer un commentaire