-
-
Save joseh-henrique/5987af821a153cdd83e3a69a48144175 to your computer and use it in GitHub Desktop.
Cloudinary + Carrierwave + Heroku + Railsでの画像を手軽に利用する方法 ref: http://qiita.com/GenTamura84/items/38cf899827bba050a21c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= form_for(@user) do |f| %> | |
<% if @user.errors.any? %> | |
<div id="error_explanation"> | |
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2> | |
<ul> | |
<% @user.errors.full_messages.each do |msg| %> | |
<li><%= msg %></li> | |
<% end %> | |
</ul> | |
</div> | |
<% end %> | |
<div class="field"> | |
<%= f.label :name %><br /> | |
<%= f.text_field :name %> | |
</div> | |
<div class="field"> | |
<%= image_tag(@user.avatar_url(:thumbnail), :width => 80, :height => 80) %> | |
<%= f.file_field :avatar %> | |
<%= f.check_box :remove_avatar %> 画像を削除する | |
<%= f.hidden_field :avatar_cache %> | |
</div> | |
<div class="actions"> | |
<%= f.submit %> | |
</div> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
class AvatarUploader < CarrierWave::Uploader::Base | |
include Cloudinary::CarrierWave | |
process :convert => 'png' | |
process :tags => ['avatar'] | |
version :standard do | |
process :resize_to_fill => [100, 150, :north] | |
end | |
version :thumbnail do | |
process :resize_to_fit => [50, 50] | |
end | |
def public_id | |
return model.id ・・・※1 | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$heroku open |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
gem 'rails', '3.2.8' | |
gem 'carrierwave' | |
gem 'cloudinary' | |
gem 'heroku' | |
group :test, :development do | |
gem 'sqlite3' | |
end | |
group :production do | |
gem 'pg' | |
gem 'thin' | |
end | |
group :assets do | |
gem 'sass-rails', '~> 3.2.3' | |
gem 'coffee-rails', '~> 3.2.1' | |
gem 'uglifier', '>= 1.0.3' | |
end | |
gem 'jquery-rails' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Listing users</h1> | |
<table> | |
<tr> | |
<th>Name</th> | |
<th></th> | |
<th></th> | |
<th></th> | |
</tr> | |
<% @users.each do |user| %> | |
<tr> | |
<td><%= user.name %></td> | |
<td><%= link_to 'Show', user %></td> | |
<td><%= link_to 'Edit', edit_user_path(user) %></td> | |
<td><%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %></td> | |
</tr> | |
<% end %> | |
</table> | |
<br /> | |
<%= link_to 'New User', new_user_path %> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CloudinaryDemo::Application.routes.draw do | |
resources :users | |
root :to => 'users#index' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p id="notice"><%= notice %></p> | |
<p> | |
<b>Name:</b> | |
<%= @user.name %> | |
</p> | |
<p> | |
<b>Avatar:</b> | |
<%= image_tag(@user.avatar_url) %> | |
</p> | |
<%= link_to 'Edit', edit_user_path(@user) %> | | |
<%= link_to 'Back', users_path %> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
attr_accessible :avatar, :avatar_cache, :name, :remove_avatar | |
mount_uploader :avatar, AvatarUploader | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment