mercredi 5 août 2015

Error in saving two files in two different model using paperclip rails 3.0.6. The id filed in both tables is "id"

View (Form)
<%= form_for @tablet,:html => { :multipart => true } do |f| %>
    <div class="form-group"> 
    <%= f.label :image , "Pill Image"%><br />
    <%= f.file_field :image %>
  </div>
  <div class="form-group"> 
    <%= f.fields_for :audio_attributes do |f1| %>
       <%= f1.label :asset , "Pill Audio"%><br />
      <%= f1.file_field :asset %>enter code here
    <% end %>
  </div>

Controller
   @tablet = Tablet.new(params[:tablet])
   @tablet.audio= [Audio.new(params[:tablet [:audio_attributes])]
   @tablet.save

Model 1 
class Tablet < ActiveRecord::Base
    has_many :audio
    accepts_nested_attributes_for :audio, allow_destroy: true
    attr_accessible :image
    has_attached_file :image, :styles => { :medium => "300x300>"}
    validates_attachment :image, :content_type => { :content_type => /\Aimage\/.*\Z/ }
end

Model 2 
class Audio < ActiveRecord::Base
   set_table_name("audio")
   belongs_to :tablet
   attr_accessible :asset
   has_attached_file :asset
   validates_attachment :asset, :content_type => { :content_type => /\Aaudio\/.*\Z/ }
end

Question : How can I save two images in different model despite having same id fields in tables ?

It does not save two files in two different model if id fields in both tables are same "id"

Aucun commentaire:

Enregistrer un commentaire