Awesome, thanks for the continued help. I tried the first thing you
suggested, putting in the default AJAX settings. Being an
inexperienced Rails programmer, I really don’t know what you mean by
number 2. How do I sort my rails headers? I’m fairly sure I’m
running Rails 2.2.2
A few more things that I tried: setting the ‘accepts’ hash to be
{ script: “text/javascript” }, and the ‘dataType’ string to be
“script”. Neither of these seem to work. I also tried doing the
RAILS_DEFAULT_LOGGER.debug “rendering html”, and I also added to it so
that I can see what some of the request headers:
RAILS_DEFAULT_LOGGER.debug “rendering script; accepts:#
{request.accepts}, method:#{request.method}”
and lo and behold: it’s rendering HTML, and simply passing right over
the js area. Here’s what the logger outputted:
The first submit, where the entry is initially saving:
Processing BlogEntriesController#create (for 127.0.0.1 at 2009-02-22
23:46:30) [POST]
Session ID: fun!
Parameters: {“authenticity_token”=>“fun!”, “blog_entry”=>
{“title”=>“asdf”, “content”=>“asdf”}}
[4;35;1mUser Columns (3.6ms) SHOW FIELDS FROM users
[4;36;1mUser Load (0.3ms) SELECT * FROM users
WHERE (users
.id
= 1) LIMIT 1
[4;35;1mBlog Load (0.9ms) SELECT * FROM blogs
WHERE
(blogs
.user_id = 1) LIMIT 1
[4;36;1mBlog Columns (3.5ms) SHOW FIELDS FROM blogs
[4;35;1mBlogEntry Columns (1.6ms) SHOW FIELDS FROM blog_entries
[4;36;1mSQL (1.6ms) BEGIN
[4;35;1mBlogEntry Create (0.4ms) INSERT INTO blog_entries
(last_edited_at
, updated_at
, title
, published
, blog_id
,
summary
, content
, first_published_at
, flag_count
,
created_at
) VALUES(NULL, ‘2009-02-23 04:46:30’, ‘asdf’, 0, 1, NULL,
‘asdf’, NULL, NULL, ‘2009-02-23 04:46:30’)
[4;36;1mSQL (0.5ms) COMMIT
rendering script; accepts:text/javascripttext/htmlapplication/xml*/*,
method:post
Rendering blog_entries/create
Completed in 50ms (View: 2, DB: 13) | 200 OK [http://localhost/
blog_entries]
Now the second submit, where it’s supposed to be putting (and seems to
be):
Processing BlogEntriesController#update (for 127.0.0.1 at 2009-02-22
23:48:59) [PUT]
Session ID: dogs
Parameters: {“commit”=>“Save”, “authenticity_token”=>“yay”,
“id”=>“64”, “blog_entry”=>{“title”=>“asdf”, “content”=>“asdf”}}
[4;35;1mUser Columns (16.9ms) SHOW FIELDS FROM users
[4;36;1mUser Load (2.2ms) SELECT * FROM users
WHERE (users
.id
= 1) LIMIT 1
[4;35;1mBlogEntry Columns (1.8ms) SHOW FIELDS FROM blog_entries
[4;36;1mBlogEntry Load (0.4ms) SELECT blog_entries
.* FROM
blog_entries
INNER JOIN blogs ON blog_entries.blog_id = blogs.id
WHERE (blog_entries
.id
= 64 AND ((blogs
.user_id = 1)))
[4;35;1mSQL (0.1ms) BEGIN
[4;36;1mSQL (0.1ms) COMMIT
rendering html; accepts:text/htmlapplication/xml*/*, method:put <—
**** THERE’S THE PROBLEM ****
Redirected to #BlogEntry:0x246321c
Completed in 143ms (DB: 22) | 302 Found [http://localhost/blog_entries/
64]
And, since it redirects as stated, there’s also the rendering of the
[GET] after that. This is really stumping me. I’m beginning to
wonder if anyone else has actually tried this sort of thing and
succeeded. The thing is that I’m trying to be RESTful, so I’m trying
to use the model/controller links that are already there, because this
is the first app I’m building and I want to do it right.
I also thought that maybe it was because I was using the
remote_form_for helper, so I changed the form to use the
form_remote_tag helper. The same as before ensued. So for some
reason, when the form is being submitted the second time, jQuery
forgets to tell Rails that it accepts javascript? I really don’t
understand why this is happening
So the question is, how do I get the correct accept header sent the
second time? And WHY THE HECK IS IT CHANGING!?! It’s the same freakin
form for goodness sake!!
Thank you again for bearing with me, as I’m new, and I hope we can get
this figured out.
GrooveAwesome, thanks for the continued help. I tried the first thing
you suggested, putting in the default AJAX settings. Being an
inexperienced Rails programmer, I really don’t know what you mean by
number 2. How do I sort my rails headers? I’m fairly sure I’m
running Rails 2.2.2
A few more things that I tried: setting the ‘accepts’ hash to be
{ script: “text/javascript” }, and the ‘dataType’ string to be
“script”. Neither of these seem to work. I also tried doing the
RAILS_DEFAULT_LOGGER.debug “rendering html”, and I also added to it so
that I can see what some of the request headers:
RAILS_DEFAULT_LOGGER.debug “rendering script; accepts:#
{request.accepts}, method:#{request.method}”
and lo and behold: it’s rendering HTML, and simply passing right over
the js area. Here’s what the logger outputted:
The first submit, where the entry is initially saving:
Processing BlogEntriesController#create (for 127.0.0.1 at 2009-02-22
23:46:30) [POST]
Session ID: fun!
Parameters: {“authenticity_token”=>“fun!”, “blog_entry”=>
{“title”=>“asdf”, “content”=>“asdf”}}
[4;35;1mUser Columns (3.6ms) SHOW FIELDS FROM users
[4;36;1mUser Load (0.3ms) SELECT * FROM users
WHERE (users
.id
= 1) LIMIT 1
[4;35;1mBlog Load (0.9ms) SELECT * FROM blogs
WHERE
(blogs
.user_id = 1) LIMIT 1
[4;36;1mBlog Columns (3.5ms) SHOW FIELDS FROM blogs
[4;35;1mBlogEntry Columns (1.6ms) SHOW FIELDS FROM blog_entries
[4;36;1mSQL (1.6ms) BEGIN
[4;35;1mBlogEntry Create (0.4ms) INSERT INTO blog_entries
(last_edited_at
, updated_at
, title
, published
, blog_id
,
summary
, content
, first_published_at
, flag_count
,
created_at
) VALUES(NULL, ‘2009-02-23 04:46:30’, ‘asdf’, 0, 1, NULL,
‘asdf’, NULL, NULL, ‘2009-02-23 04:46:30’)
[4;36;1mSQL (0.5ms) COMMIT
rendering script; accepts:text/javascripttext/htmlapplication/xml*/*,
method:post
Rendering blog_entries/create
Completed in 50ms (View: 2, DB: 13) | 200 OK [http://localhost/
blog_entries]
Now the second submit, where it’s supposed to be putting (and seems to
be):
Processing BlogEntriesController#update (for 127.0.0.1 at 2009-02-22
23:48:59) [PUT]
Session ID: dogs
Parameters: {“commit”=>“Save”, “authenticity_token”=>“yay”,
“id”=>“64”, “blog_entry”=>{“title”=>“asdf”, “content”=>“asdf”}}
[4;35;1mUser Columns (16.9ms) SHOW FIELDS FROM users
[4;36;1mUser Load (2.2ms) SELECT * FROM users
WHERE (users
.id
= 1) LIMIT 1
[4;35;1mBlogEntry Columns (1.8ms) SHOW FIELDS FROM blog_entries
[4;36;1mBlogEntry Load (0.4ms) SELECT blog_entries
.* FROM
blog_entries
INNER JOIN blogs ON blog_entries.blog_id = blogs.id
WHERE (blog_entries
.id
= 64 AND ((blogs
.user_id = 1)))
[4;35;1mSQL (0.1ms) BEGIN
[4;36;1mSQL (0.1ms) COMMIT
rendering html; accepts:text/htmlapplication/xml*/*, method:put <—
**** THERE’S THE PROBLEM ****
Redirected to #BlogEntry:0x246321c
Completed in 143ms (DB: 22) | 302 Found [http://localhost/blog_entries/
64]
And, since it redirects as stated, there’s also the rendering of the
[GET] after that. This is really stumping me. I’m beginning to
wonder if anyone else has actually tried this sort of thing and
succeeded. The thing is that I’m trying to be RESTful, so I’m trying
to use the model/controller links that are already there, because this
is the first app I’m building and I want to do it right.
I also thought that maybe it was because I was using the
remote_form_for helper, so I changed the form to use the
form_remote_tag helper. The same as before ensued. So for some
reason, when the form is being submitted the second time, jQuery
forgets to tell Rails that it accepts javascript? I really don’t
understand why this is happening
So the question is, how do I get the correct accept header sent the
second time? And WHY THE HECK IS IT CHANGING!?! It’s the same freakin
form for goodness sake!!
Thank you again for bearing with me, as I’m new, and I hope we can get
this figured out.
Groove