无法上传图片(回形针)和jQuery Mobile [英] can't upload image (paperclip) and jquery mobile

查看:123
本文介绍了无法上传图片(回形针)和jQuery Mobile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法保存头像(图片)

获取此消息: 1个错误禁止保存此通知: 阿凡达を入力してください.

get this message : 1 error prohibited this notice from being saved: Avatarを入力してください。

development.log

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/"

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

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

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

models/notice.rb

models/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

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

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

controllers/notices_controller.rb

controllers/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

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

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

views/notices/_form.html.haml

views/notices/_form.html.haml

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

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

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

schema.rb

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

非常感谢有人读过它:)

Thank you very much if someone even read it :)

推荐答案

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

Thank you guys for reading all this stuff :)

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

THE solution -> I had to add "data-ajax" => false :), cuz I use jquery mobile :)

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

:)

这篇关于无法上传图片(回形针)和jQuery Mobile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆