Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Image Uploads in Ruby on Rails 4.1

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 %> <% 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

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