【发布时间】:2011-04-01 12:49:41
【问题描述】:
我在使用 Rails 和 jQuery 上传文件时遇到问题,我使用的是 attachment_fu 插件。
我正在尝试上传(创建)属于相册的照片资源。相册有很多照片。
这是我在 application.js 中编写的 jQuery 代码
$("#new_photo").submit(function(){
$.post($(this).attr("action")+'.js', $(this).serialize(), null, "script");
return false;
});
但是,创建新专辑的类似 jQuery 代码工作正常! 这是在 application.js 中创建新专辑的 jQuery 代码
$("#new_album").submit(function(){
$.post($(this).attr("action")+'.js', $(this).serialize(), null, "script");
return false;
});
意见/照片/new.html.erb
<h1>New photo</h1>
<% form_for([@album, @photo], :html => {:multipart => true}) do |f| %>
<%= f.error_messages %>
<%= render :partial => "form", :object => f %>
<%= f.submit "Create"%>
<% end %>
<%= link_to 'Back', [@album, @photo], :method => :get %>
这是我在尝试创建新照片时在日志中遇到的错误:
Processing PhotosController#create to js (for 127.0.0.1 at 2011-04-01 17:41:52) [POST]
Parameters: {"format"=>"js", "album_id"=>"1",
"action"=>"create",
"authenticity_token"=>"k1Y1ILWbLFWYFaCwpkwW/W13aPe8UPoV0Fd+naO8bxU=", "controller"
=>"photos"}
User Columns (0.0ms) SHOW FIELDS FROM `users`
User Load (0.0ms) SELECT * FROM `users` WHERE (`users`.`id` = 1) LIMIT 1
Album Columns (0.0ms) SHOW FIELDS FROM `albums`
Album Load (15.6ms) SELECT * FROM `albums` WHERE (`albums`.`id` = 1)
Photo Columns (15.6ms) SHOW FIELDS FROM `photos`
SQL (0.0ms) BEGIN
Photo Create (0.0ms) Mysql::Error: Column 'filename' cannot be null: INSERT INTO
`photos` (`size`, `created_at`, `content_type`, `tag_id`, `album_id`,
`thumbnail`, `updated_at`, `filename`, `height`, `parent_id`, `width`) VALUES(NULL,
'2011-04-01 12:11:52', NULL, NULL, 1, NULL, '2011-04-01 12:11
:52', NULL, NULL, NULL, NULL)
SQL (0.0ms) ROLLBACK
ActiveRecord::StatementInvalid (Mysql::Error: Column 'filename' cannot be null:
INSERT INTO `photos` (`size`, `created_at`, `content_type`, `tag_id`,
`album_id`, `thumbnail`, `updated_at`, `filename`, `height`, `parent_id`, `width`)
VALUES(NULL, '2011-04-01 12:11:52', NULL, NULL, 1, NULL, '2011-04-0
12:11:52', NULL, NULL, NULL, NULL)):
Rendered rescues/_trace (203.1ms)
Rendered rescues/_request_and_response (0.0ms)
Rendering rescues/layout (internal_server_error)
Problems loading RmagickProcessor: no such file to load -- RMagick2.so
escues/layout (internal_server_error)
SQL (0.0ms) SET NAMES 'utf8'
SQL (0.0ms) SET SQL_AUTO_IS_NULL=0
我还启用了use_accept_header 以在我的config/environment.rb 文件中接受.js 格式为
config.action_controller.use_accept_header = true
【问题讨论】:
标签: jquery ruby-on-rails