无法上传图片(回形针)和jquery手机

时间:2013-04-11 09:32:38

标签: ruby-on-rails jquery-mobile paperclip paperclip-validation

无法保存头像(图片)

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

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)

设定:

配置/环境/ development.rb     Paperclip.options [:command_path] =“/ usr / local / bin /”

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

模型/ notice.rb

class Notice < ActiveRecord::Base
attr_accessible :admin_id, :message, :seat
attr_accessible :avatar
has_attached_file :avatar, :styles => { :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

非常感谢有人甚至读过它:)

2 个答案:

答案 0 :(得分:1)

替换

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

通过

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

答案 1 :(得分:1)

谢谢大家阅读所有这些内容:)

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

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

:)

相关问题