使用Rails 3.1.1,1.9.2紅寶石, 寶石:寶石 'HAML',創業板simple_form「,創業板 'AWS-SDK',
寶石「回形針」,:git的=> 「GIT中://github.com/thoughtbot/paperclip.git」
插件:country_select:GIT中://github.com/rails/country_select.git回形針 「寶石」 的Rails 3.1未定義的方法模型文件名
有一個問題上傳/顯示圖像推送到亞馬遜S3通過回形針(GEM) 錯誤:undefined方法`avatar_file_name'的#Player:0x00000102aff228
大部分我是在git上的例子對於回形針 https://github.com/thoughtbot/paperclip
這裏-hub頁是我在我的代碼:
遷移: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文件: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
...
研究: 我發現很多事情要做遷移的pluging和genration但是這一切似乎老了。他們中的大多數人建議在遷移過程中爲這四個屬性進行優化。然而,它似乎應該已被替換爲一行t.has_attached_file:頭像。
我有一個rails 3.0項目,這工作。我能夠上傳產品並將其拉回。 (必須使用建議的image_tag @ icon.avatar.url並將其轉換爲%img {:src => URI.unescape(icon.icon.url)},但這是一個不同的問題。)