2013-05-15 25 views
1

我發現了類似的問題,但我的是有點不同。
(回形針3.4.1,Rails的3.2.12,紅寶石1.9.3p392,使用戰俘0.40)回形針寶石崩潰在Rails的用戶的會話

這裏是我的模型:

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) 

而且遵循的是什麼日誌顯示,當我上傳的文件通槽這兩種驗證方法。所以這個錯誤只出現在文件沒有驗證的時候。檢查:

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: "[email protected]", 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") 

我很迷路。 有什麼幫助嗎?

UPDATE:

這裏是我的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:

在#[email protected]大家講到這裏問我我的形式。 然後我意識到我手動設置了authenticity_token,你可以看到here。現在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> 

我惹毛了。

+0

你可以發表你的表格嗎?我認爲你的問題來自csrf令牌,就像日誌中的警告所說的那樣。如果您未通過令牌授權,會話將被清除。所以請檢查你的csrf的東西.. – Mattherick

+1

嗯,我認爲,一切都是確定的形式。因爲當我在上傳中使用良好的圖像時(圖像將通過回形針驗證器)沒有問題發生。但確定,這是它:https://gist.github.com/anonymous/5582495 – fschuindt

+1

同樣的問題在這裏 – Daniel

回答

4

我今天碰到這個問題,它看起來像它與力量屬性而非回形針的問題,與此相關的:https://github.com/37signals/pow/issues/125

我只設法得到它的工作通過使用戰俘作爲港口代理的WEBrick而不是作爲一個機架應用程序,希望這也可以幫助你。