ruby on rails - How to Associate 5 atmost pictures with a account -


i have model company has_many :company_pictures @ 5 photos. have show user 5 file field image uploading.

class company < activerecord::base   has_many :company_pictures   accepts_nested_attributes_for :company_pictures end  class companypicture < activerecord::base     belongs_to :company     has_attached_file :picture, :styles => { :medium => "300x300>"} end 

controller code

def new     @company = company.new     5.times { @company.company_pictures.build } end 

now through in new form able show 5 file field. on submit . let form did not saved because of other error. find file field hold value that. want make sure user able attach @ 5 photos whether creating new company or updating company.

what in cases before presenting user "new" layout, create , save object first in database "draft" status objective of getting primary key , able save pictures (the pictures need primary key in order saved). then, when user submits form, no matter if there errors or not save pictures , present user form, errors (in case there are) , since images got saved database can display them user. if there no errors remove "draft" status user , continue workflow.

now question is, drafts ? create rake task run's every hour , delete records in state.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -