Hello,
I have one controller that has two routes. One is a "direct" route and
the other is a nested resource under another object. The two URLs are:

http://example.com/controller
http://example.com/nested/controller

I have an AJAX form that submits data to a method via the GET method
and then renders a JS ERB template to execute some Javascript and
update a div. This works as expected with the nested route. However
the bare or "direct" route's request headers that are sent to
controller from the AJAX call are "text/html,application/xhtml
+xml,application/xml;q=0.9,*/*;q=0.8" vs the proper "*/*;q=0.5, text/
javascript, application/javascript, application/ecmascript,
application/x-ecmascript".

I have tried different ways to force the client to send the request
headers as javascript:

- Setting data-type attribute to script in the form
- Setting the headers["Content-Type"] to "text/javascript;
charset=utf-8" in the controller
- Adding :format => :js in the URL path helper method

I know I have tried more but I cannot remember all that i have tried
in the last two days trying to figure this out. What is weird is how
the same code works for the nested route but does not work for the
bare version. I am using Rails 3.1.3 with Ruby 1.9.3p0.

Thanks for any help,
Jarod

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Draiken at Apr 17, 2012 at 1:41 pm
    This is probably a problem with the request and not the response.
    Rails will give you what you ask on headers. So if your AJAX call is
    asking for html, it's giving HTML and not JS.

    Check if you're really asking for javascript on the ajax call's
    headers, and please post how you're making this calls.
    On Apr 16, 12:05 pm, Jarod Watkins wrote:
    Hello,
    I have one controller that has two routes. One is a "direct" route and
    the other is a nested resource under another object. The two URLs are:

    http://example.com/controllerhttp://example.com/nested/controller

    I have an AJAX form that submits data to a method via the GET method
    and then renders a JS ERB template to execute some Javascript and
    update a div. This works as expected with the nested route. However
    the bare or "direct" route's request headers that are sent to
    controller from the AJAX call are "text/html,application/xhtml
    +xml,application/xml;q=0.9,*/*;q=0.8" vs the proper "*/*;q=0.5, text/
    javascript, application/javascript, application/ecmascript,
    application/x-ecmascript".

    I have tried different ways to force the client to send the request
    headers as javascript:

    - Setting data-type attribute to script in the form
    - Setting the headers["Content-Type"]  to "text/javascript;
    charset=utf-8" in the controller
    - Adding :format => :js in the URL path helper method

    I know I have tried more but I cannot remember all that i have tried
    in the last two days trying to figure this out. What is weird is how
    the same code works for the nested route but does not work for the
    bare version. I am using Rails 3.1.3 with Ruby 1.9.3p0.

    Thanks for any help,
    Jarod
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedApr 17, '12 at 3:14a
activeApr 17, '12 at 1:41p
posts2
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Draiken: 1 post Jarod Watkins: 1 post

People

Translate

site design / logo © 2022 Grokbase