Hi!
First of all i''m a newbie myself, so there may be some errors in this
code. I had the same problem lately and i solved it thanks to people on
this forum.
If you want your cars to have many images than you have to change your
tables a bit: now you have image_id foreign key in cars table. This way
if you want to have a car with 4 images you''d have to have 4 rows with
the same car data and just different image_id.
You should remove this foreign key and create new ''car_id'' in
images
table.
This way every row in images table will specify a single image. If you
have many images with the same car_id they will all belong to one car,
so this car will have many images.
Then you need to specify in your Car model:
has_many :images, :dependent => true
and in your Image model:
belongs_to :car
file_column :image
Now if you want to upload many images in a single form you should
(probably) change this line in file_column source code. If you will
upload just one image at a time, you don''t need to do this.
In file_column_helper.rb change in the first method:
result = ActionView::Helpers::InstanceTag.new(object.dup,
method.to_s+"_temp", self).to_input_field_tag("hidden", {})
to this:
result = ActionView::Helpers::InstanceTag.new(object.dup,
method.to_s+"_temp", self).to_input_field_tag("hidden",
options)
Now you can create many file_column_fields like this:
<% 5.times do |i| %>
<% @image = @images[i] %>
<%= file_column_field "image", "name",
"index" => i %>
<% end %>
And to display them later:
<% @car.images.each do |image| %>
<%= image_tag url_for_file_column( "image", "image")
%>
<% end %>
If you don''t know how to create code for your car controller, look for
the topic "How to save parent and child objects in a single action".
--
Posted via http://www.ruby-forum.com/.