Paperclip gem is crashing the user's session in Rails -
i have found similar questions that, mine little bit different.
(paperclip 3.4.1, rails 3.2.12, ruby 1.9.3p392, using pow 0.40)
here model:
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 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. jpg/jpeg or png accepted." [...] end
where '[...]' omitted unrelated stuffs.
when validates_attachment_size or validates_attachment_content_type gives fail, error occur , session data cleaned (even login).
that's appears in application logs, check it:
started post "/smokes" 127.0.0.1 @ 2013-05-14 23:48:38 -0300 processing smokescontroller#create html warning: can't verify csrf token authenticity redirected http://weedmap.dev/login filter chain halted :deny_unlogged_users rendered or redirected completed 302 found in 9ms (activerecord: 2.4ms)
and follow log shows when uploaded file pass trough these 2 validation methods. error appears when file not validate. check:
started post "/smokes" 127.0.0.1 @ 2013-05-14 23:33:33 -0300 processing smokescontroller#create 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".* "users" "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 "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 "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")
i pretty lost. help?
update:
here part of 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
update 2:
talking on #rubyonrails@freenode.net asked me form. realized setting authenticity_token manually can see here. form_tag doing automatically. (the rails default don't knew)
anyway, here form, , still same error, same thing:
<div id="new-smoke-form"> <%= form_tag '/smokes', :multipart => true, :method => "post" %> <%= hidden_field_tag 'latitude', @smoke.latitude %> <%= hidden_field_tag 'longitude', @smoke.longitude %> <div id="new-smoke-picture"> <p>upload picture (optional):</p> <%= file_field_tag 'picture' %> <div class="clear"> </div> </div> <div id="new-smoke-description"> <p>talk 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>
i getting mad.
i came across issue today, looks it's issue pow rather paperclip, related this: https://github.com/37signals/pow/issues/125
i've managed working using pow port proxy webrick instead of rack app, helps too.
Comments
Post a Comment