-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create image_posting_function of micropost
- Loading branch information
Showing
12 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,5 @@ | |
/tmp | ||
/vendor/bundle | ||
/database.sqlite | ||
/public/uploads/tmp/ | ||
/public/uploads/micropost/image/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,5 @@ gem 'jbuilder', '1.5.3' | |
group :doc do | ||
gem 'sdoc', '0.4.1', require: false | ||
end | ||
gem 'carrierwave' | ||
gem 'rmagick' |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
class ImageUploader < CarrierWave::Uploader::Base | ||
# Include RMagick or MiniMagick support: | ||
include CarrierWave::RMagick | ||
# include CarrierWave::MiniMagick | ||
|
||
# Choose what kind of storage to use for this uploader: | ||
storage :file | ||
# storage :fog | ||
|
||
# Override the directory where uploaded files will be stored. | ||
# This is a sensible default for uploaders that are meant to be mounted: | ||
#画像ファイルのパス | ||
def store_dir | ||
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" | ||
end | ||
|
||
# Provide a default URL as a default if there hasn't been a file uploaded: | ||
# def default_url(*args) | ||
# # For Rails 3.1+ asset pipeline compatibility: | ||
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) | ||
# | ||
# "/images/fallback/" + [version_name, "default.png"].compact.join('_') | ||
# end | ||
|
||
# Process files as they are uploaded: | ||
#表示画像サイズ制限調整 | ||
# process scale: [200, 300] | ||
#process :resize_to_fit => [200, 200] | ||
process :resize_to_limit => [300, 300] | ||
# def scale(width, height) | ||
# # do something | ||
# end | ||
|
||
# Create different versions of your uploaded files: | ||
#サムネイル画像サイズ | ||
version :thumb do | ||
process resize_to_fit: [50, 50] | ||
end | ||
|
||
#version :profile do | ||
# process :resize_to_fill => [150, 150, gravity = ::Magick::CenterGravity] | ||
#end | ||
# Add a white list of extensions which are allowed to be uploaded. | ||
# For images you might use something like this: | ||
# def extension_whitelist | ||
# %w(jpg jpeg gif png) | ||
# end | ||
|
||
# jpg,jpeg,gif,pngしか受け付けない | ||
def extension_white_list | ||
%w(jpg jpeg gif png) | ||
end | ||
|
||
#ファイルサイズ制限 | ||
def size_range | ||
1..9.megabytes | ||
end | ||
# Override the filename of the uploaded files: | ||
# Avoid using model.id or version_name here, see uploader/store.rb for details. | ||
# def filename | ||
# "something.jpg" if original_filename | ||
# 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddImagesToMicroposts < ActiveRecord::Migration | ||
def change | ||
add_column :microposts, :image, :string | ||
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