-
Notifications
You must be signed in to change notification settings - Fork 0
Paperclip in Rails 3
richlewis14 edited this page Dec 1, 2012
·
1 revision
Paperclip allows you to save images to the model.. It comes with 2 default size settings but has the capacity to build custom sizes aswell.
Firstly you need to install the gem rmagick
When resizing you add the dimensions within the model where the images are being saved, in this example the recipe model
has_attached_file :avatar, :styles => { :showrecipe => "500x500>", :medium => "300x300>", :thumb => "100x100>" }
I have added the :showrecipe dimensions already
When you want to call that paticular size you pass the params ( :showrecipe) after the url, eg
<%= image_tag @recipe.avatar.url(:showrecipe) %>
However, if you have any images that where uploaded before the change then it will not take effect, there are 1 of 2 things you can do
#Console Recipe.each_find { |u| u.avatar.reprocess!}
#Command Line paperclip:refresh rake
Now when you refresh the page your image will be resized