Rails 및 jQuery를 사용하여 파일을 업로드하는 데 문제가 있습니다. attachment_fu 플러그인을 사용하고 있습니다.jQuery/Javascript를 사용하여 Rails에서 Ajaxy 파일 업로드 문제가 발생했습니다.
앨범에 속한 사진 자료를 업로드 (생성)하려고합니다. 그리고 앨범에는 많은 사진이 있습니다.
여기 내가 application.js
$("#new_photo").submit(function(){
$.post($(this).attr("action")+'.js', $(this).serialize(), null, "script");
return false;
});
하지만에 작성한 jQuery 코드입니다, 새 앨범을 만들 수있는 유사한 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 %>
그리고 내가하려고 할 때 로그에서 얻을 오류입니다 application.js를 만들 jQuery 코드입니다 새로운 사진을 만들 :
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
을 나는 또한로 내 config/environment.rb
파일에 .js
형식을 허용하도록 use_accept_header
을 사용하도록 설정config.action_controller.use_accept_header = true
나는 그 일을 serialize하는 것에 의심의 여지가있었습니다. 아마 맞을 것입니다. Plupload와 SWFupload를 모두 사용해 보겠습니다. – Vineeth