2

无法保存头像(图片)

收到此消息:1个错误禁止保存此通知:头像を入力してください。</p>

开发日志

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 < 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
...

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

架构.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

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

4

2 回答 2

1

通过替换解决

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

经过

:url  => ":attachment/:id/:style/:filename"
于 2013-04-11T09:38:23.807 回答
1

谢谢你们阅读所有这些东西:)

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

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

:)

于 2013-04-11T10:39:30.533 回答