I have a rails app that consists of a CMS system that I use in order to enter sights from a city to my database. I am using paperclip to upload images to amazon s3. All is working fine. Now I want my json files that an ios app will use to include the urls of the images uploaded in s3. I have seen some answers here but I cannot seem to make my code work. What I have is this..
place model
attr_accessible :assets_attributes, :asset
has_many :assets
accepts_nested_attributes_for :assets, :allow_destroy => true
asset model
class Asset < ActiveRecord::Base
attr_accessible :asset_content_type, :asset_file_name, :asset_file_size, :asset_updated_at, :place_id, :asset
belongs_to :place
has_attached_file :asset
validates_attachment :asset, :presence => true,
:content_type => { :content_type => ['image/jpeg', 'image/png'] },
:size => { :in => 0..1.megabytes }
end
view code
<%= f.fields_for :assets do |asset_fields| %>
<% if asset_fields.object.new_record? %>
<p>
<%= asset_fields.file_field :asset %>
</p>
<% end %>
<% end %>
<br/>
<%= f.fields_for :assets do |asset_fields| %>
<% unless asset_fields.object.new_record? %>
<%= link_to image_tag(asset_fields.object.asset.url(:original), :class => "style_image"), (asset_fields.object.asset.url(:original)) %>
<%= asset_fields.check_box :_destroy %>
<% end %>
<% end %>
places controller
def index
@places = Place.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @places }
end
end
Can anyone please help me?