私はそれに似た質問を見つけましたが、私の質問は少し異なります。
(Paperclip 3.4.1、Rails 3.2.12、Ruby 1.9.3p392、Pow 0.40 を使用)
これが私のモデルです:
class Smoke < ActiveRecord::Base
[...]
attr_accessible :latitude, :longitude, :description, :picture
validates_length_of :description, :minimum => 2, :maximum => 256, :allow_blank => true
validates_presence_of :latitude, :longitude
scope :with_picture, where("picture_file_name IS NOT NULL")
belongs_to :user
has_many :comments, :dependent => :destroy
has_many :smoke_reports, :dependent => :destroy
has_attached_file :picture,
:default_url => "/assets/missing/:style.jpg",
:styles => { :thumb => ["55x55", :jpg], :medium => ["500x500", :jpg], :original => ["800x800", :jpg] },
:storage => :s3,
:bucket => 'my-bucket-dev',
:path => "/:class/:style/:id.:extension",
:url => ":s3_domain_url",
:s3_credentials => {
:access_key_id => 'mys3credentials',
:secret_access_key => 'mys3credentials'
}
validates_attachment_size :picture,
:less_than => 2.megabytes
validates_attachment_content_type :picture,
:content_type => /^image\/(jpg|jpeg|pjpeg|png|x-png)$/,
:message => "Invalid image type. Only jpg/jpeg or png will be accepted."
[...]
end
ここで '[...]' 関係のないものは省略しました。
validates_attachment_size または validates_attachment_content_type が失敗すると、何らかのエラーが発生し、すべてのセッション データ (ログインも含む) が消去されます。
アプリケーションログに表示されるのはこれだけです。確認してください。
Started POST "/smokes" for 127.0.0.1 at 2013-05-14 23:48:38 -0300
Processing by SmokesController#create as HTML
WARNING: Can't verify CSRF token authenticity
Redirected to http://weedmap.dev/login
Filter chain halted as :deny_unlogged_users rendered or redirected
Completed 302 Found in 9ms (ActiveRecord: 2.4ms)
以下は、アップロードしたファイルがこれら 2 つの検証方法を通過したときにログに表示される内容です。したがって、このエラーは、ファイルが検証されない場合にのみ表示されます。小切手:
Started POST "/smokes" for 127.0.0.1 at 2013-05-14 23:33:33 -0300
Processing by SmokesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"DU+9CCVAzIxBbeccCWR1z4IzfQHxpiht6xPVCS/q3tc=", "latitude"=>"58.81374171570781", "longitude"=>"77.87109375", "picture"=>#<ActionDispatch::Http::UploadedFile:0x007f9f9c17e330 @original_filename="Untitled-1.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"picture\"; filename=\"Untitled-1.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:/var/folders/6n/2zzqcbfd1c51xz1phh8sz17h0000gn/T/RackMultipart20130514-59252-1xbz3zf>>, "description"=>"", "commit"=>"Create"}
User Load (0.8ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/6n/2zzqcbfd1c51xz1phh8sz17h0000gn/T/Untitled-120130514-59252-bu86an.jpg[0]'
Command :: convert '/var/folders/6n/2zzqcbfd1c51xz1phh8sz17h0000gn/T/Untitled-120130514-59252-bu86an.jpg[0]' -auto-orient -resize "800x800" '/var/folders/6n/2zzqcbfd1c51xz1phh8sz17h0000gn/T/Untitled-120130514-59252-bu86an20130514-59252-l87c43.jpg'
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/6n/2zzqcbfd1c51xz1phh8sz17h0000gn/T/Untitled-120130514-59252-bu86an20130514-59252-l87c4320130514-59252-km9don.jpg[0]'
Command :: convert '/var/folders/6n/2zzqcbfd1c51xz1phh8sz17h0000gn/T/Untitled-120130514-59252-bu86an20130514-59252-l87c4320130514-59252-km9don.jpg[0]' -auto-orient -resize "55x55" '/var/folders/6n/2zzqcbfd1c51xz1phh8sz17h0000gn/T/Untitled-120130514-59252-bu86an20130514-59252-l87c4320130514-59252-km9don20130514-59252-4r2p3r.jpg'
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/6n/2zzqcbfd1c51xz1phh8sz17h0000gn/T/Untitled-120130514-59252-bu86an20130514-59252-l87c4320130514-59252-km9don.jpg[0]'
Command :: convert '/var/folders/6n/2zzqcbfd1c51xz1phh8sz17h0000gn/T/Untitled-120130514-59252-bu86an20130514-59252-l87c4320130514-59252-km9don.jpg[0]' -auto-orient -resize "500x500" '/var/folders/6n/2zzqcbfd1c51xz1phh8sz17h0000gn/T/Untitled-120130514-59252-bu86an20130514-59252-l87c4320130514-59252-km9don20130514-59252-1byzja6.jpg'
(0.2ms) BEGIN
SQL (1.1ms) INSERT INTO "smokes" ("created_at", "description", "latitude", "longitude", "picture_content_type", "picture_file_name", "picture_file_size", "picture_updated_at", "updated_at", "user_id") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING "id" [["created_at", Wed, 15 May 2013 02:33:33 UTC +00:00], ["description", ""], ["latitude", 58.81374171570781], ["longitude", 77.87109375], ["picture_content_type", "image/jpeg"], ["picture_file_name", "Untitled-1.jpg"], ["picture_file_size", 8623], ["picture_updated_at", Wed, 15 May 2013 02:33:33 UTC +00:00], ["updated_at", Wed, 15 May 2013 02:33:33 UTC +00:00], ["user_id", nil]]
SQL (0.7ms) INSERT INTO "versions" ("created_at", "event", "ip", "item_id", "item_type", "object", "whodunnit") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["created_at", Wed, 15 May 2013 02:33:33 UTC +00:00], ["event", "create"], ["ip", "127.0.0.1"], ["item_id", 17], ["item_type", "Smoke"], ["object", nil], ["whodunnit", #<User id: 1, name: "Fernando Schuindt", email: "f.schuindtcs@gmail.com", password_digest: nil, created_at: "2013-05-07 23:23:42", updated_at: "2013-05-10 06:18:41", external_provider: true, avatar_setup: 3>]]
[paperclip] Saving attachments.
[paperclip] saving /smokes/original/17.jpg
[AWS S3 200 2.147466 0 retries] put_object(:acl=>:public_read,:bucket_name=>"weedsquare-dev",:content_length=>8623,:content_type=>"image/jpeg",:data=>Paperclip::FileAdapter: Untitled-120130514-59252-bu86an20130514-59252-l87c43.jpg,:key=>"smokes/original/17.jpg")
私はかなり迷っています。何か助けはありますか?
アップデート:
ここに私の SmokesController の一部があります:
class SmokesController < ApplicationController
before_filter :deny_unlogged_users, :except => [:new, :show, :count, :refresh_profile]
before_filter :only_ajax, :only => [:new, :count, :refresh_profile]
before_filter :only_with_smoke_params, :only => [:create]
[...]
def create
@user = current_user
@smoke = Smoke.new
@smoke.latitude = params[:latitude]
@smoke.longitude = params[:longitude]
@smoke.picture = params[:picture]
@smoke.description = params[:description]
if @smoke.save
@user.smokes << @smoke
redirect_to @smoke
else
render 'new'
end
end
[...]
end
更新 2:
これについて #rubyonrails@freenode.net で話していると、みんなが私のフォームについて尋ねてきました。次に、ここで見られるように、authenticity_token を手動で設定していたことに気付きました。これで、form_tag が自動的にそれを行います。(Railsはデフォルトでそれを行いますが、私は知りませんでした)
とにかく、ここに私のフォームがありますが、それでも同じエラー、同じことです:
<div id="new-smoke-form">
<%= form_tag '/smokes', :multipart => true, :method => "post" do %>
<%= hidden_field_tag 'latitude', @smoke.latitude %>
<%= hidden_field_tag 'longitude', @smoke.longitude %>
<div id="new-smoke-picture">
<p>Upload a picture (optional):</p>
<%= file_field_tag 'picture' %>
<div class="clear">
</div>
</div>
<div id="new-smoke-description">
<p>Talk about it:</p>
<div id="new-smoke-remain" class="new-smoke-remain">256</div>
<%= text_area_tag 'description', nil, :class => "new-smoke-textarea", :id => "new-smoke-textarea" %>
</div>
<%= submit_tag "Create", :class => "new-smoke-button" %>
<% end %>
</div>
私は怒っています。