“协会类型不匹配”?在回形针

时间:2011-12-07 12:40:45

标签: ruby-on-rails-3 paperclip

我正在使用paperclip来上传用户avatar.Evrery的东西运作良好但是当我点击保存按钮时我收到了错误:

    ActiveRecord::AssociationTypeMismatch in UsersController#update

    Usernote(#79841148) expected, got Array(#25890648)

    Request

Parameters:

{"authenticity_token"=>"bLhGiceEIEohpuuclDpbmpzJR7SFb4HEY4+Qy9ER20E=",
 "_method"=>"put",
 "utf8"=>"✓",
 "id"=>"2",
 "user"=>{"user_information"=>{"passport_number"=>"",
 "passport_expiry_date"=>"",
 "gender"=>"Male",
 "birth_date"=>"",
 "marriage_date"=>"",
 "present_address"=>"",
 "blood_group"=>"",
 "emergency_contact"=>"",
 "marital_status"=>"Married"},
 "usernotes"=>{"notes"=>"Hi this is First note from Ritz"},
 "designation_id"=>"2",
 "username"=>"ritz",
 "reporting_to_id"=>"",
 "avatar"=>#<ActionDispatch::Http::UploadedFile:0x9514578 @headers="Content-Disposition: form-data; name=\"user[avatar]\"; filename=\"child ravi.jpg\"\r\nContent-Type: image/jpeg\r\n",
 @content_type="image/jpeg",
 @original_filename="child ravi.jpg",
 @tempfile=#<File:C:/Users/user/AppData/Local/Temp/RackMultipart20111207-2300-3nkxr9-0>>,
 "last_name"=>"roshan",
 "user_salary_detail"=>{"work_phone"=>"",
 "EPS_account_number"=>"",
 "work_type"=>"Permanent",
 "date_of_joining"=>"",
 "work_location"=>"",
 "branch"=>"",
 "PF_account_number"=>"",
 "bank_name"=>"",
 "PAN"=>"",
 "status"=>"Active",
 "bank_account_number"=>""},
 "password"=>"[FILTERED]",
 "department_id"=>"1",
 "first_name"=>"hritwik",
 "email"=>"rvdthakur@yahoo.com"}}

这是我的模特:

class User < ActiveRecord::Base
   has_attached_file :avatar,
                    :styles => {
                      :thumb => "75x75#",
                      :small => "100x100#",
                      :medium => "150x150>"
                    },
                    :default => :thumb,
                    :url => "/users/user_avatar/:attachment/:id/:style/:basename.:extension",  
                    :path => ":profitnext/public/images/users/user_avatar/:attachment/:id/:style/:basename.:extension"  

# avatar validations
  validates_attachment_size :avatar, :less_than => 5.megabytes
  validates_attachment_content_type :avatar, :content_type => ['image/jpeg', 'image/png'] 
end

和我的观点:

<%= image_tag @user.avatar.url %>
              <%= image_tag @user.avatar.url(:thumb) %>

点击保存按钮后出现错误。我正在努力解决这个问题。提前谢谢。

1 个答案:

答案 0 :(得分:1)

我的猜测是,这与回形针无关,但更像是this。您的用户模型中是否有has_many :usernotes和/或Usernote模型中有belongs_to :user