script/generate paperclip product photo
rake db:migrate
# models/product.rb
has_attached_file :photo, :styles => { :small => "150x150>" },
:url => "/assets/products/:id/:style/:basename.:extension",
:path => ":rails_root/public/assets/products/:id/:style/:basename.:extension"
validates_attachment_presence :photo
validates_attachment_size :photo, :less_than => 5.megabytes
validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/png']
# views
<%= image_tag @product.photo.url(:small) %>
<% form_for @product, :html => { :multipart => true } do |f| %>
...
<%= f.file_field :photo %>
...
<% end %>
- Railscasts
- Thoughtbot
- Jimneath
- Thewebfellas - Advance and Detailed Tutorial
0 comments:
Post a Comment