背景:私はRails 3.0.3、MySQL、Ruby 1.9.2-p136を使用しています。ペーパークリップの検証に失敗しましたファイル名を設定する必要があります
宝石関連:
宝石 'レール'、 '3.0.3'
宝石 'mysql2'
宝石 'jqueryのレール'、 '> = 1.0.3'
宝石'client_side_validations'
宝石 'rails3-jqueryの - オートコンプリート'
宝石 '熊手'、 '〜> 0.8.7'
宝石 "query_reviewer"、:gitの=>「gitの://github.com/nesquena/query_reviewer .git "
'gs = // gith://github.com/thoughtbot/paperclip.git'
gem 'aws-s3': gem 'paperclip'、 '〜> 2.3'、:git = 宝石「カンカン」
宝石「工夫」
宝石「simple_form」
宝石「雷」
問題:私はAmazon S3のサーバーにペーパークリップを経由して画像をアップロードしようとし、それよ検証をパスしません。具体的に私が手にメッセージは次のとおりです。
検証は失敗しました:誰かが私が間違って行ってきたところ、それははるかに高く評価されるだろう教えて助けることができる場合は写真のファイル名が
を設定する必要があります。
私のソースコードの一部です。
モデル:
Class Transaction < ActiveRecord::Base
attr_accessible :amount, :user_id, :group_id, :photo
belongs_to :users
belongs_to :groups
has_attached_file :photo,
:styles => {
:thumb=> "100x100#",
:small => "200x200>",
:large => "600x400>" },
:storage => :s3,
:s3_credentials => "#{Rails.root.to_s}/config/s3.yml",
:path => "/:attachment/:id/:style.:extension"
validates_attachment_presence :photo
validates_attachment_size :photo, :less_than => 5.megabytes
validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/png', 'image/jpg']
end
コントローラー:
class TransactionsController < ApplicationController
def confirm
end
def create
@transaction = Transaction.new(params[:transaction])
if @transaction.save!
render 'confirm'
else
redirect_to :back
end
end
ビュー:
<%= form_for(@transaction, :url => transactions_path, :html => { :mulitpart => true }, :validate => true) do |t| %>
<%= t.hidden_field :user_id, :value => current_user.id %>
<%= t.label "Select Group:" %>
<%= t.select :group_id, options_from_collection_for_select(@groups, :id, :name), :class => "ui-corner-all" %><br />
<%= t.label "Amount:" %>
$ <%= t.text_field :amount, :size => 20 %> <br />
<%= t.label "Receipt:" %>
<%= t.file_field :photo, :size => 20 %> <br />
<%= t.submit 'Continue', :name => "withdrawal" %>
<% end %>
のconfig/s3.yml:
development:
bucket: trans-dev
access_key_id: MY_ID
secret_access_key: MY_KEY
test:
bucket: trans-test
access_key_id: MY_ID
secret_access_key: MY_KEY
production:
bucket: trans-pro
access_key_id: MY_ID
secret_access_key: MY_KEY
schema.rb:
create_table "transactions", :force => true do |t|
t.integer "amount", :default => 0, :null => false
t.integer "user_id", :null => false
t.integer "group_id", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.string "photo_file_name"
t.string "photo_content_type"
t.integer "photo_file_size"
t.datetime "photo_updated_at"
end
は、私が知っている私が言うとき:transaction.save @
!
ブラウザにエラーメッセージが表示されます。私がそれを置かなければ、それは保存されず、私はフォームにリダイレクトされます。私は多くのチュートリアルを読んだことがあります。実際にこれをやったので、なぜうまくいかないのか本当に混乱しています。私はそれをHerokuにアップロードして、それがうまくいくかどうか見てみましたが、失敗しました。
ありがとうございます、ご意見ありがとうございます。
編集:私のサーバーからのメッセージです。
Started POST "/transactions" for 127.0.0.1 at 2011-07-12 18:25:12 -0400
Processing by TransactionsController#create as HTML
Parameters: {"utf8"=>"✓",
"authenticity_token"=>"y8hAJq7+SGP4qEcWOBz/hmlIzgeCgEuqayY5EluMt18=", "transaction"=>
{"user_id"=>"7", "group_id"=>"2", "amount"=>"3.25", "description"=>"plz work!",
"purpose"=>"0", "item_category"=>"0", "photo"=>"Ctrl Alt Del.jpeg"}, "countdown"=>"91",
"withdrawal"=>"Continue"}
Group Load (0.3ms) SELECT SQL_NO_CACHE `groups`.* FROM `groups` WHERE (`groups`.`id` = 2) LIMIT 1
SQL (0.2ms) BEGIN
SQL (0.2ms) ROLLBACK
Completed in 143ms
ActiveRecord::RecordInvalid (Validation failed: Photo file name must be set):
app/controllers/transactions_controller.rb:15:in `create'