Topic: problems with ajax around nested resources

hi all,

the nested resources are Template and Entry 

  resources :templates do
    resources :entries 
  end

the entries are listed int Template' index.html.erb

and the code of  the Entry's create.js.erb are

$("#<%= dom_id @template %> .entries").css('display', 'table');
$('<%= j render @entry %>').appendTo($("#<%= dom_id @template %> .entries")).hide().fadeIn();
$("#<%= dom_id @template %> .template_form").html("");

it works fine when i input words assign to Entry's invariable,the url all stay in /templates


but when i bond a Entry's invariable together with the Uploader of the CarrierWave gem,

then i click Create Entry the url is localhost:3000/templates/:template_id/entries


why?  and when i delete the /:template_id/entries of that url then it show normally


how to modify the code to make the url stay in /templates or redirect back to /templates?


many thank!

i am a rails rookie

Re: problems with ajax around nested resources

the log error warning:

Started GET "/templates/2/entries/new?utf8=%E2%9C%93&entry_type=entry_image&commit=Add+a+Image" for 127.0.0.1 at 2012-06-19 10:04:39 +0800
Processing by EntriesController#new as JS
  Parameters: {"utf8"=>"✓", "entry_type"=>"entry_image", "commit"=>"Add a Image", "template_id"=>"2"}
  Template Load (10.5ms)  SELECT `templates`.* FROM `templates` WHERE `templates`.`id` = 2 LIMIT 1
  Rendered common/_form_error.html.erb (0.1ms)
  Rendered entries/_form.html.erb (177.9ms)
  Rendered entries/new.js.erb (185.6ms)
Completed 200 OK in 203ms (Views: 189.2ms | ActiveRecord: 10.5ms)
[2012-06-19 10:04:39] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true


Started POST "/templates/2/entries" for 127.0.0.1 at 2012-06-19 10:04:51 +0800
Processing by EntriesController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"Y1qzd80TjZiV3wb4tRpvULBKRaaHWN4ITIPtU1BKkS4=", "entry"=>{"name"=>"jay", "image"=>#<ActionDispatch::Http::UploadedFile:0x957fe8c @original_filename="P5010004.JPG", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"entry[image]\"; filename=\"P5010004.JPG\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:/tmp/RackMultipart20120619-13259-vmt7hc>>, "remote_image_url"=>""}, "commit"=>"Create Entry", "template_id"=>"2"}
  Template Load (4.5ms)  SELECT `templates`.* FROM `templates` WHERE `templates`.`id` = 2 LIMIT 1
   (7.0ms)  BEGIN
  SQL (0.7ms)  INSERT INTO `entries` (`content`, `created_at`, `image`, `name`, `template_id`, `updated_at`) VALUES (NULL, '2012-06-19 02:04:52', 'P5010004.JPG', 'jay', 2, '2012-06-19 02:04:52')
   (3.3ms)  COMMIT
   (0.4ms)  BEGIN
   (0.2ms)  COMMIT
Completed 406 Not Acceptable in 271ms (ActiveRecord: 16.0ms)

when i input word,the correct log info

Started GET "/templates/2/entries/new?utf8=%E2%9C%93&entry_type=entry_link&commit=Add+a+Link" for 127.0.0.1 at 2012-06-19 10:02:22 +0800
Processing by EntriesController#new as JS
  Parameters: {"utf8"=>"✓", "entry_type"=>"entry_link", "commit"=>"Add a Link", "template_id"=>"2"}
  Template Load (0.2ms)  SELECT `templates`.* FROM `templates` WHERE `templates`.`id` = 2 LIMIT 1
  Rendered common/_form_error.html.erb (0.1ms)
  Rendered entries/_form.html.erb (24.4ms)
  Rendered entries/new.js.erb (25.9ms)
Completed 200 OK in 36ms (Views: 29.1ms | ActiveRecord: 0.2ms)
[2012-06-19 10:02:22] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true


Started POST "/templates/2/entries" for 127.0.0.1 at 2012-06-19 10:02:51 +0800
Processing by EntriesController#create as JS
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"Y1qzd80TjZiV3wb4tRpvULBKRaaHWN4ITIPtU1BKkS4=", "entry"=>{"name"=>"jay", "content"=>"railsforum.com"}, "commit"=>"Create Entry", "template_id"=>"2"}
  Template Load (7.3ms)  SELECT `templates`.* FROM `templates` WHERE `templates`.`id` = 2 LIMIT 1
   (0.3ms)  BEGIN
  SQL (14.5ms)  INSERT INTO `entries` (`content`, `created_at`, `image`, `name`, `template_id`, `updated_at`) VALUES ('railsforum.com', '2012-06-19 02:02:51', NULL, 'jay', 2, '2012-06-19 02:02:51')
   (3.3ms)  COMMIT
   (0.6ms)  BEGIN
   (0.2ms)  COMMIT
  Template Load (10.0ms)  SELECT `templates`.* FROM `templates` WHERE `templates`.`id` = 2 LIMIT 1
  Rendered entries/_entry.html.erb (14.6ms)
  Rendered entries/create.js.erb (17.3ms)
Completed 200 OK in 59ms (Views: 15.4ms | ActiveRecord: 36.1ms)

by comparing the two set of data, the cause of error is  Create is processed as HTML

Started POST "/templates/2/entries" for 127.0.0.1 at 2012-06-19 10:04:51 +0800
Processing by EntriesController#create as HTML

and that should be procesed as JS.

inut words and load image use the same Action, and in resopnd_to only exists format.js

i'm confused with the error...

i am a rails rookie

Re: problems with ajax around nested resources

it's ok with the remotipart gem

https://github.com/JangoSteve/remotipart

i am a rails rookie