我正在尝试使用有效的管理员上传图片。我没有错误但它什么也没做。这是一个例子:
模型 post.rb
class Post < ActiveRecord::Base
has_attached_file :image, styles: { medium: "300x300>", thumb: "100x100>" }, default_url: "/images/:style/missing.png"
validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/
belongs_to :category
end
admin_post.rb
ActiveAdmin.register Post do
permit_params :title,:image
# CKEDITOR
form do |f|
f.inputs do
f.input :title
f.input :image, :required => false, :as => :file
end
f.submit
end
index do
column :title
actions
end
show do |ad|
attributes_table do
row :title
row :image do
image_tag(ad.image.url(:thumb))
end
# Will display the image on show object page
end
end
end
迁移文件
class AddAttachmentImageToPosts < ActiveRecord::Migration
def up
add_attachment :posts, :image
end
def down
remove_attachment :posts, :image
end
end
我有一个posgres数据库,它只更新字段“Title”
添加图片时,这是日志文件:
Started POST "/admin/posts" for ::1 at 2016-04-15 10:10:10 +0200
ActiveRecord::SchemaMigration Load (0.5ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by Admin::PostsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"hJyaD6nfKLVKb1AXzTBQCe5cD6jpM6OBtr57MtssHtEILHclXt0lWka7RvSK6ttHRM7jnS04GTF2EdUnXNsa5A==", "post"=>{"title"=>"maquette", "image"=>#<ActionDispatch::Http::UploadedFile:0x84d0548 @tempfile=#<Tempfile:C:/Users/Bastou/AppData/Local/Temp/RackMultipart20160415-105332-926dwu.jpg>, @original_filename="maquette.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"post[image]\"; filename=\"maquette.jpg\"\r\nContent-Type: image/jpeg\r\n">}, "commit"=>"Create Post"}
AdminUser Load (1.0ms) SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = $1 ORDER BY "admin_users"."id" ASC LIMIT 1 [["id", 1]]
Unpermitted parameter: image
(0.0ms) BEGIN
SQL (1.0ms) INSERT INTO "posts" ("title", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["title", "maquette"], ["created_at", "2016-04-15 08:10:10.437177"], ["updated_at", "2016-04-15 08:10:10.437177"]]
(2.5ms) COMMIT
Redirected to http://localhost:3000/admin/posts/17
Completed 302 Found in 439ms (ActiveRecord: 10.0ms)
Started GET "/admin/posts/17" for ::1 at 2016-04-15 10:10:10 +0200
Processing by Admin::PostsController#show as HTML
Parameters: {"id"=>"17"}
AdminUser Load (0.0ms) SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = $1 ORDER BY "admin_users"."id" ASC LIMIT 1 [["id", 1]]
Post Load (0.5ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = $1 LIMIT 1 [["id", 17]]
Rendered c:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/bundler/gems/active_admin-d84f8190edac/app/views/active_admin/resource/show.html.arb (1316.0ms)
Completed 200 OK in 1433ms (Views: 1426.0ms | ActiveRecord: 0.5ms)
Started GET "/images/thumb/missing.png" for ::1 at 2016-04-15 10:10:12 +0200
ActionController::RoutingError (No route matches [GET] "/images/thumb/missing.png"):
actionpack (4.2.5.1) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
web-console (2.3.0) lib/web_console/middleware.rb:28:in `block in call'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `catch'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `call'
actionpack (4.2.5.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.5.1) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.5.1) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.5.1) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.5.1) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.5.1) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.5.1) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.5.1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.4) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.5.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
actionpack (4.2.5.1) lib/action_dispatch/middleware/static.rb:116:in `call'
rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
railties (4.2.5.1) lib/rails/engine.rb:518:in `call'
railties (4.2.5.1) lib/rails/application.rb:165:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
rack (1.6.4) lib/rack/content_length.rb:15:in `call'
rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
c:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
c:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
c:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
Rendered c:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-4.2.5.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (2.0ms)
Rendered c:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-4.2.5.1/lib/action_dispatch/middleware/templates/routes/_route.html.erb (3.0ms)
Rendered c:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-4.2.5.1/lib/action_dispatch/middleware/templates/routes/_table.html.erb (8.0ms)
Rendered c:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-4.2.5.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.0ms)
Rendered c:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-4.2.5.1/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout (885.9ms)
Rendered c:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/web-console-2.3.0/lib/web_console/templates/_markup.html.erb (0.5ms)
Rendered c:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/web-console-2.3.0/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (0.5ms)
Rendered c:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/web-console-2.3.0/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (0.5ms)
Rendered c:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/web-console-2.3.0/lib/web_console/templates/style.css.erb within layouts/inlined_string (0.5ms)
Rendered c:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/web-console-2.3.0/lib/web_console/templates/console.js.erb within layouts/javascript (555.0ms)
Rendered c:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/web-console-2.3.0/lib/web_console/templates/main.js.erb within layouts/javascript (0.0ms)
Rendered c:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/web-console-2.3.0/lib/web_console/templates/error_page.js.erb within layouts/javascript (0.5ms)
Rendered c:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/web-console-2.3.0/lib/web_console/templates/index.html.erb (1282.9ms)