Hi everyone,
I''m trying to connect an uploaded image (using act_as_attachment) to an
item in my database. Uploading the image in itself is no problem, though
I can''t seem to get the foreign-id to "stick".
I''ve set up my models (image.rb and item.rb). In image.rb I''ve
setup the
"belongs_to :item"-association and created an "item_id" in
my
images-table using migrations (and I''ve confirmed it has been in fact
created in YourSQL).
In my uploads-controller I''ve setup the following:
def new
@item = Item.find(params[:id])
@image = Image.new
end
def create
@image = Image.create!(params[:image])
@image.item = params[:id]
redirect_to :action => ''list''
end
(I''ve tried switching @image.item to @image.item_id, and params[:id] to
params[:item])
To upload a new image I enter the URL: "/uploads/new/12". My
uploads-view looks like this:
<p>Product: <%= @item.name %></p>
<% form_for :image, :url => { :action => ''create'' },
:html => {
:multipart => true } do |f| -%>
<p><%= f.file_field :uploaded_data %></p>
<p><%= submit_tag :Create %></p>
<% end -%>
My log shows no command to input item_id to be found...
Processing UploadsController#create (for 127.0.0.1 at 2007-03-03
20:05:55) [POST]
Session ID: fd42ffbe649cc70a002b53acd94926e1
Parameters: {"commit"=>"Create",
"action"=>"create",
"controller"=>"uploads",
"image"=>{"uploaded_data"=>#<File:/tmp/CGI.830.1>}}
Image Columns (0.037518) SHOW FIELDS FROM images
SQL (0.002857) BEGIN
SQL (0.000795) INSERT INTO images (`content_type`, `item_id`,
`size`, `thumbnail`, `db_file_id`, `filename`, `height`, `parent_id`,
`width`) VALUES(''image/jpeg'', NULL, 168427, NULL, NULL,
''DSC00414.jpg'',
428, NULL, 640)
SQL (0.029149) COMMIT
Thanks for any help!
Best regards,
Gustav
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---