Search code examples
ruby-on-railsjquery-mobilepaperclippaperclip-validation

can't upload image (paperclip) and jquery mobile


Can't save avatar(image)

get this message : 1 error prohibited this notice from being saved: 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)

Settings:

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

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

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

# 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

= 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

Thank you very much if someone even read it :)


Solution

  • Thank you guys for reading all this stuff :)

    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|
    

    :)