I have a model called Listing. In my index.html.erb for listings. I have all the listings on the screen. The _form.html.erb for the Listing model look like this:
<%if user_signed_in? %>
<%=link_to "Sign Out", destroy_user_session_path, :method => :delete %><br/>
<%= form_for(@listing, :html => {:multipart => true} ) do |f| %>
<% if @listing.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@listing.errors.count, "error") %> prohibited this listing from being saved:</h2>
<ul>
<% @listing.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :id %><br />
<%= f.text_field :id %>
</div>
<%= f.label :image %>
<%= f.file_field :image %>
<%= f.submit %>
<% end %>
<%else%>
<%=link_to "Sign in", new_user_session_path %>
Contact the admin to obtain a login and password
<%end%>
Here the model associated with this view is "Listing", but I would like to store the uploaded image attributes in a different model in the app: "Image".
Basically what Im trying to do is, make all my models upload their own photos through their views but save all the image attributes in a single model called "Image". And the images themselves are stored on Amazon S3.
So the question is what code goes in the "Listing" model to make this happen and what code goes in the "Image" model to make this happen. And how does this information get passed from the Listing to the Image?
Currently in the Listing model:
class Listing < ActiveRecord::Base
has_attached_file :image,:styles => {:thumb => "75x75>", :small => "150x150>", :medium => "300x300>"}
end
Currently in the "Image"model
# == Schema Information
#
# Table name: images
#
# id :integer not null, primary key
# image_file_name :string(255)
# image_content_type :string(255)
# image_file_size :integer
# image_type :string(255)
# created_at :datetime not null
# updated_at :datetime not null
#
class Image < ActiveRecord::Base
end
Thanks in advance for your help.