Hey there, I want to be able to upload multiple images at once on my
website. I can only upload one image at a time at the moment. Can
anybody lead me in the right direction? Here's my code






/app/models/listing.rb



class Listing < ActiveRecord::Base
has_attached_file :image, :styles => { :medium => "200x", :thumb =>
"100x100>" }, :default_url => "default.jpg"
validates_attachment_content_type :image, :content_type =>
/\Aimage\/.*\Z/
end










/app/controllers/listings_controller.rb



...
private
# Use callbacks to share common setup or constraints between actions.
def set_listing
@listing = Listing.find(params[:id])
end

# Never trust parameters from the scary internet, only allow the white
list through.
def listing_params
params.require(:listing).permit(:name, :description, :price, :image)
end
end







/app/views/listings/_form.html.erb



<%= form_for @listing, :html => { :multipart => true } do |f| %>
...
...
<div class="form-group">
<%= f.file_field :image, class: "form-control" %>
</div>
<div class="form-group">
<%= f.submit class: "btn btn-primary" %>
</div>
<% end %>









/app/views/listings/show.html.erb



<p id="notice"><%= notice %></p>

<%= image_tag @listing.image.url(:medium) %>
...








/app/views/listings/index.html.erb



<h1>Listing listings</h1>

<table>
<thead>
<tr>
<th>Image</th>
<th>Name</th>
...
<tbody>
<% @listings.each do |listing| %>
<tr>
<td><%= image_tag listing.image.url(:medium) %></td>
<td><%= listing.name %></td>
...

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/d48357fe24cbe0c57ec356c6d00c2ab1%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to