Hi all. I''ve gotten the acts_as_attachment tutorial to work just fine.
However now i''m trying to do something that''s not covered and
keep
running into a brick wall. I''m pretty sure this is a simple concept
that I''m just not familiar with yet.
I''d like to association an image with a entry from a different model. I
suppose in other words I''m asking how to update two models from one
controllers create action. Example:
class TrackImage < ActiveRecord::Base
belongs_to :track
acts_as_attachment :storage => :file_system, :max_size =>
300.kilobytes, :content_type => :image
validates_as_attachment
end
class Track < ActiveRecord::Base
has_many :track_images
end
class Admin::TracksController < ApplicationController
## stuff omitted for brevity''s sake
def create
@track = Track.new(params[:track])
if @track.save
flash[:notice] = ''Track was successfully created.''
@track_image = TrackImage.create! params[:track_image]
redirect_to :action => ''list''
else
render :action => ''new''
end
end
end
## new.rhtml ##
<%= form_tag({:action => ''create''}, :multipart =>
true) %>
<%= render :partial => ''form'' %>
<%= submit_tag "Create" %>
<%= end_form_tag %>
<%= link_to ''Back'', :action => ''list''
%>
## _form.rhtml ##
## stuff omitted for brevity''s sake
<p><%= file_field ''track'',
''track_image'' %></p>
The above code is producting this error:
undefined method `track_image='' for #<Track:0x2278e10>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---