をレール、Rubyの1.9.2、 宝石:宝石 'HAML'、宝石 'simple_form'、宝石 'AWS-SDK'、
宝石「クリップ」、:gitの=> "gitの://github.com/thoughtbot/paperclip.git"
プラグイン:country_select:gitの://github.com/rails/country_select.gitペーパークリップ "宝石" のレール3.1.1を使用して3.1未定義のメソッドモデルファイル名
/発行アップロードを持つ表示を私はgitの上の例を次れたほとんどの部分について0x00000102aff228
:未定義のメソッド `avatar_file_name」を#Playerため:画像は(GEM) エラークリップを通じてアマゾンS3にプッシュ
移行:20111224044508_create_players.rb
class CreatePlayers < ActiveRecord::Migration
def change
create_table :players do |t|
t.string :first_name
t.boolean :first_name_public, :default => false
...
t.string :website
t.boolean :website_public, :default => false
t.has_attached_file :avatar
t.timestamps
end
end
end
モデル:Player.rb:
class Player < ActiveRecord::Base
attr_accessible :first_name, ... :website
validates_presence_of :username, :email
has_attached_file :avatar,
:styles => { :medium => "300x300>", :thumb => "100x100>" },
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:path => ":class/:id/:style/:filename"
{Unrelated validations}
end
S3クリップ ここhttps://github.com/thoughtbot/paperclip
ため-hubページには、私は私のコードで持っているものですファイル:s3.yml
development:
bucket: voh_development
access_key_id: *********************
secret_access_key: ********************
staging:
bucket: voh_staging
access_key_id: *********************
secret_access_key: ********************
production:
bucket: voh_production
access_key_id: *********************
secret_access_key: ********************
コントローラー:players_controller.rb
class PlayersController < ApplicationController
def create
@player = Player.create(params[:player])
if @player.save
redirect_to players_path, :notice => "Player Created";
else
render :action => 'new'
end
end
{basic restful}
end
再生回数: Edit.html.haml + New.html.haml
= simple_form_for @player do |f|
= f.input :first_name
...
= f.input :website
= f..file_field :avatar
.input_div
= f.button :submit
index.html.haml
...
%td Avatar
%td First Name
...
%td Actions
- @players.each do |player|
%tr
%td
= image_tag @player.avatar.url(:thumb)
%td
= player.first_name
...
%td
= link_to ' Show ', player_path(player.id)
|
= link_to ' Edit ', edit_player_path(player.id)
ショー。 html.haml
= image_tag @user.avatar.url
%br
= @player.first_name
...
Research: マイグレーションのplugingとgenrationとはかなり関係がありましたが、すべて古いようです。それらの大部分は、4つの属性の移行の際に上に置くことを提案します。しかし、それは1行t.has_attached_file:アバターに置き換えられているはずです。
私には3.0のプロジェクトがあり、これはうまくいきました。私は製品をアップロードして元に戻すことができます。 (提案されたimage_tag @ icon.avatar.urlで遊んで、それを%img {:src => URI.unescape(icon.icon.url)}に変えなければならなかったのですが、別の質問です)