「Attachment_fuプラグイン」の編集履歴(バックアップ)一覧はこちら
Attachment_fuプラグイン - (2008/03/07 (金) 21:03:50) の1つ前との変更点
追加された行は緑色になります。
削除された行は赤色になります。
**プラグイン名
Attachment_fuプラグイン
**このプラグインができること
+acts_as_attachmentの機能改良版。
+ファイル(特に画像)のアップロードや表示を効率化できる
+ファイルアップロード時に複数サイズのサムネイルを生成できる(要RMagick)
+ファイルの保存先はファイルシステムかDBかを選択できる。AmazonのS3サービスにも対応しているらしい。
+画像表示時のヘルパーもついてる
**対象バージョン
1.2系
**ちょー簡単な使い方
>script/plugin install http://svn.techno-weenie.net/projects/plugins/attachment_fu/
でインストールして、
>class CreateMugshots < ActiveRecord::Migration
> def self.up
> create_table :mugshots do |t|
> t.column :parent_id, :integer
> t.column :content_type, :string
> t.column :filename, :string
> t.column :thumbnail, :string
> t.column :size, :integer
> t.column :width, :integer
> t.column :height, :integer
> end
> end
> def self.down
> drop_table :mugshots
> end
>end
こんな感じのテーブル作って、マイグレートできたらモデルに
>class Mugshot < ActiveRecord::Base
> has_attachment :content_type => :image,
> :storage => :file_system,
> :max_size => 3000.kilobytes,
> # :resize_to => '320x200>',
> :thumbnails => { :thumb => '100x100>', :small => '50x50>' }
> validates_as_attachment
>end
てな具合にアップロード時の設定を書いておいて、
>class MainController < ApplicationController
> def new
> @mugshot = Mugshot.new
> end
> def create
> @mugshot = Mugshot.new(params[:mugshot])
> if @mugshot.save
> flash[:notice] = 'Mugshot was successfully created.'
> redirect_to '/main/index'
> else
> render :action => :new
> end
> end
> def index
> @mugshots = Mugshot.find(:all,
> :conditions => ["parent_id is null"]
> )
> end
>end
とかってコントローラーを作って、index用のviewは
><h1>Sample Index</h1>
><% for mugshot in @mugshots -%>
> <%= link_to image_tag(mugshot.public_filename(:small)), mugshot.public_filename %>
><% end -%>
><%= link_to 'new', {:action => :new} %>
new用のviewは
><%= error_messages_for :mugshot %>
><% form_for(:mugshot, :url => 'create',
> :html => { :multipart => true }) do |f| -%>
> <p>
> <label for="mugshot">Upload A Mugshot:</label>
> <%= f.file_field :uploaded_data %>
> </p>
> <p>
> <%= submit_tag 'Create' %>
> </p>
><% end -%>
><%= link_to 'index', {:action => :index} %>
で使えるはず。
(モロパクなので[[cuspos diary Ruby on Railsファイルアップロードプラグイン attachment_fu>>http://d.hatena.ne.jp/cuspos/20071110/1194642860#20071110f2]]を参考にしてください)
**公式ページ
-どこなんでしょう?
**日本語解説ページ
-[[cuspos diary Ruby on Railsファイルアップロードプラグイン attachment_fu>>http://d.hatena.ne.jp/cuspos/20071110/1194642860#20071110f2]]
※基本的な使い方はこれでOK
※日本にもユーザーが結構居るようで、ググればノウハウも結構溜まっているみたい。
**外国語解説ページ
-[[Mike Clark's Weblog File Upload Fu>>http://clarkware.com/cgi/blosxom/2007/02/24]]
※結構良い
**のうはう
-こういうのこそポリモーフィック関連を使えば楽なのかも(未実践)
-ひとつのモデルに画像とかPDFとかExcelファイルとか入れても大丈夫なのかなぁ?(実践中)
**コメント
#pcomment(reply)
**プラグイン名
Attachment_fuプラグイン
**このプラグインができること
+acts_as_attachmentの機能改良版。
+ファイル(特に画像)のアップロードや表示を効率化できる
+ファイルアップロード時に複数サイズのサムネイルを生成できる(要RMagick)
+ファイルの保存先はファイルシステムかDBかを選択できる。AmazonのS3サービスにも対応しているらしい。
+画像表示時のヘルパーもついてる
**対象バージョン
1.2系
**ちょー簡単な使い方
>script/plugin install http://svn.techno-weenie.net/projects/plugins/attachment_fu/
でインストールして、
>class CreateMugshots < ActiveRecord::Migration
> def self.up
> create_table :mugshots do |t|
> t.column :parent_id, :integer
> t.column :content_type, :string
> t.column :filename, :string
> t.column :thumbnail, :string
> t.column :size, :integer
> t.column :width, :integer
> t.column :height, :integer
> end
> end
> def self.down
> drop_table :mugshots
> end
>end
こんな感じのテーブル作って、マイグレートできたらモデルに
>class Mugshot < ActiveRecord::Base
> has_attachment :content_type => :image,
> :storage => :file_system,
> :max_size => 3000.kilobytes,
> # :resize_to => '320x200>',
> :thumbnails => { :thumb => '100x100>', :small => '50x50>' }
> validates_as_attachment
>end
てな具合にアップロード時の設定を書いておいて、
>class MainController < ApplicationController
> def new
> @mugshot = Mugshot.new
> end
> def create
> @mugshot = Mugshot.new(params[:mugshot])
> if @mugshot.save
> flash[:notice] = 'Mugshot was successfully created.'
> redirect_to '/main/index'
> else
> render :action => :new
> end
> end
> def index
> @mugshots = Mugshot.find(:all,
> :conditions => ["parent_id is null"]
> )
> end
>end
とかってコントローラーを作って、index用のviewは
><h1>Sample Index</h1>
><% for mugshot in @mugshots -%>
> <%= link_to image_tag(mugshot.public_filename(:small)), mugshot.public_filename %>
><% end -%>
><%= link_to 'new', {:action => :new} %>
new用のviewは
><%= error_messages_for :mugshot %>
><% form_for(:mugshot, :url => 'create',
> :html => { :multipart => true }) do |f| -%>
> <p>
> <label for="mugshot">Upload A Mugshot:</label>
> <%= f.file_field :uploaded_data %>
> </p>
> <p>
> <%= submit_tag 'Create' %>
> </p>
><% end -%>
><%= link_to 'index', {:action => :index} %>
で使えるはず。
(モロパクなので[[cuspos diary Ruby on Railsファイルアップロードプラグイン attachment_fu>>http://d.hatena.ne.jp/cuspos/20071110/1194642860#20071110f2]]を参考にしてください)
**公式ページ
-どこなんでしょう?
**日本語解説ページ
-[[cuspos diary Ruby on Railsファイルアップロードプラグイン attachment_fu>>http://d.hatena.ne.jp/cuspos/20071110/1194642860#20071110f2]]
※基本的な使い方はこれでOK
※日本にもユーザーが結構居るようで、ググればノウハウも結構溜まっているみたい。
**外国語解説ページ
-[[Mike Clark's Weblog File Upload Fu>>http://clarkware.com/cgi/blosxom/2007/02/24]]
※結構良い
**のうはう
-こういうのこそポリモーフィック関連を使えば楽なのかも(未実践)
-ひとつのモデルに画像とかPDFとかExcelファイルとか入れても大丈夫なのかなぁ?(実践中)
-RMagickがちゃんとインストールされているか心配なときは、以下のコードをirbなどで実行してみよう。ちなみに、カレントディレクトリにtest.jpgがある前提だ。
>require 'rubygems'
>require 'RMagick'
>image = "test.jpg"
>original = Magick::Image.read(image).first
>resized = original.resize_to_fit(75,100)
>resized.write("test_resized.jpg")
**コメント
#pcomment(reply)