Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple upload with Paperclip in ror
    primarykey
    data
    text
    <p>I am using paperclip to upload one photo for one building. <a href="http://www.youtube.com/watch?v=KGmsaXhIdjc" rel="nofollow">http://www.youtube.com/watch?v=KGmsaXhIdjc</a> i have done it with this way. But know I decide to upload many photos to one building. Can I do that with paperclip or have to change it and use jQuery ? And if I can how ? <strong>Ps: if needed I will upload my code. ps: i am thinking to make 2 more columns in database for photo2 and photo 3</strong>.. btw i have see all generates assets to do that. the think is that i have make it with different way to upload 1 photo. this means i have to change the all thing? </p> <p>update 1:</p> <p>in routes.rb</p> <pre><code>resources :buildings do resources :photos end </code></pre> <p>in buldings>_form</p> <pre><code>&lt;%= form_for(@building, :html=&gt;{:multipart =&gt; true}) do |f| %&gt; &lt;% if @building.errors.any? %&gt; &lt;div id="error_explanation"&gt; &lt;h2&gt;&lt;%= pluralize(@building.errors.count, "error") %&gt; prohibited this building from being saved:&lt;/h2&gt; &lt;ul&gt; &lt;% @building.errors.full_messages.each do |msg| %&gt; &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt; &lt;% end %&gt; &lt;/ul&gt; &lt;/div&gt; &lt;% end %&gt; &lt;div class="field"&gt; &lt;%= f.label :title %&gt;&lt;br /&gt; &lt;%= f.text_field :title %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :status %&gt;&lt;br /&gt; &lt;%= f.select :status, Building::STATUS, :prompt=&gt;'Select status of the building' %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :description %&gt;&lt;br /&gt; &lt;%= f.text_area :description, :rows =&gt; 10 %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :price %&gt;&lt;br /&gt; &lt;%= f.text_field :price %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;!--&lt;%= f.label :photo %&gt;&lt;br /&gt; &lt;%= f.file_field :photo %&gt; --&gt; &lt;%= f.fields_for :photos do |photo| %&gt; &lt;% if photo.object.new_record? %&gt; &lt;%= photo.file_field(:image) %&gt; &lt;% else %&gt; &lt;%= image_tag(photo.url(:thumb)) %&gt; &lt;%= photo.hidden_field :_destroy %&gt; &lt;%= photo.link_to_remove "X"%&gt; &lt;% end %&gt; &lt;% end %&gt; &lt;p&gt;&lt;%= f.link_to_add "Add photo", :photos %&gt;&lt;/p&gt; &lt;/div&gt; &lt;div class="actions"&gt; &lt;%= f.submit %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <p>in model>building</p> <pre><code> attr_accessible :description, :price, :status, :title, :photo accepts_nested_attributes_for :photo, :allow_destroy =&gt; true has_attached_file :photo , :url =&gt; "/assets/products/:id/:style/:basename.:extension", :path =&gt; ":rails_root/public/assets/products/:id/:style/:basename.:extension" </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload