无法上传图片(paperclip)和jquery mobile

无法保存头像(图片)

收到此消息:1错误禁止此通知被保存:Avatarを入力してください。

development.log

Started PUT "/notices/1" for 127.0.0.1 at 2013-04-11 18:32:59 +0900 Processing by NoticesController#update as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"m6JK3ufruxHDD84vniXEbe4SEzRijK5HTI1SF6MkTUM=", "notice"=>{"message"=>"xxx", "seat"=>"1"}, "commit"=>"Save", "id"=>"1"} User Load (2.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1 Notice Load (1.4ms) SELECT "notices".* FROM "notices" WHERE "notices"."id" = $1 LIMIT 1 [["id", "1"]] (0.3ms) BEGIN (0.2ms) ROLLBACK Rendered notices/_form.html.haml (10.7ms) Rendered notices/edit.html.haml within layouts/application (24.3ms) Completed 200 OK in 594ms (Views: 293.9ms | ActiveRecord: 18.2ms) 

设置:

config / environments / development.rb Paperclip.options [:command_path] =“/ usr / local / bin /”

====================================

车型/ notice.rb

 class Notice  { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png", :path => ":rails_root/public/system/:attachment/:id/:style/:filename", :url => "/system/:attachment/:id/:style/:filename" validates_attachment :avatar, :presence => true end 

====================================

控制器/ notices_controller.rb

 # POST /notices # POST /notices.json def create @notice = Notice.new(params[:notice]) @notice.admin_id = current_user.id respond_to do |format| if @notice.save format.html { redirect_to @notice, notice: 'Notice was successfully created.' } format.json { render json: @notice, status: :created, location: @notice } else format.html { render action: "new" } format.json { render json: @notice.errors, status: :unprocessable_entity } end end end 

====================================

意见/告示/ _form.html.haml

 = form_for @notice, :html => { :multipart => true } do |f| ... .field = f.file_field :avatar ... 

====================================

schema.rb

 `create_table "notices", :force => true do |t|` t.integer "admin_id" t.text "message" t.boolean "seat" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false t.string "avatar_file_name" t.string "avatar_content_type" t.integer "avatar_file_size" t.datetime "avatar_updated_at" end ➜ xxx git:(master) ✗ brew install imagemagick Error: imagemagick-6.8.0-10 already installed ➜ xxx git:(master) ✗ brew install gs Error: ghostscript-9.06 already installed 

非常感谢,如果有人甚至读它:)

解决了替换

 :url => "/system/:attachment/:id/:style/:filename" 

通过

 :url => ":attachment/:id/:style/:filename" 

谢谢大家阅读所有这些东西:)

解决方案 – >我不得不添加“data-ajax”=> false :),因为我使用jquery mobile 🙂

 = form_for(@notice, :html => { :multipart => true, "data-ajax" => false}) do |f| 

🙂