I'm having problems in uploading a file using Rails and jQuery, I'm using attachment_fu plugin.
I'm trying to upload(create) a photo resource that belongs to album. And album has many photos.
Here's the jQuery code i've written in application.js
$("#new_photo").submit(function(){
$.post($(this).attr("action")+'.js', $(this).serialize(), null, "script");
return false;
});
BUT, the similar jQuery code to create new album works fine! Here's the jQuery code to create new album written inside application.js
$("#new_album").submit(function(){
$.post($(this).attr("action")+'.js', $(this).serialize(), null, "script");
return false;
});
The views/photos/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 %>
And here's the error I get in the log when I try to create a new photo:
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
I've also enabled the use_accept_header to accept .js formats in my config/environment.rb file as
config.action_controller.use_accept_header = true