Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7733981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:08:09+00:00 2026-06-01T07:08:09+00:00

I’m trying to get some RJS code written with prototype and Rails 2.3.11 to

  • 0

I’m trying to get some RJS code written with prototype and Rails 2.3.11 to work in Rails 3.2.1

I have the prototype-rails gem, so render :update do |page| works, I’m using a form with :remote => true that sends an ajax request to the controller, and the javascript looks like it’s being generated ok.

However, the content-type in the header of the response is text/html; charset=utf-8, which should be text/javascript.

In the controller I’m calling it like this:

render :update do |page|
    if @step.errors.empty?
        page.redirect_to how_to_path(@article.id)
    else
        page.replace_html 'add_step_form', :partial => 'how_to/add_step', :locals => {:step => @step, :altered => true}
    end
end

It seems to generate the window.location.href... and Element.update... code ok, but it isn’t executing because the content-type is wrong.

Is there something that I might be doing wrong that could cause this? I need a solution that will make rjs with prototype work. jQuery will probably be used in the future, but making that change right now isn’t an option.

update:
I’ve tried a few other ways of writing the code, including specifying :content_type => "text/javascript" in render, wrapping it in a respond_to block with format.js, and rewriting it as js.erb file, but all still are returning with text/html as the content-type in the response header.

update
I sort of figured out how to get the expected behavior by adding headers["Content-Type"] = "text/javascript; charset=utf-8" in the controller before render, but this doesn’t really seem like the best way to do it if I have to add that explicitly before every RJS instance. I’d like a cleaner solution if anyone can come up with one.

update
It turns out we had a before_filter running before every request that was setting the content-type to text/html. I removed this, and was able to remove all of the headers["Content-Type"] code that I added. It worked in my development environment but not in our testing verification environment. That turned out to be we had old assets cached on there, so verification was running prototype 1.6.1, while my local development environment had 1.7.0. That caused rails.js not to compile in verification, so all the requests had an Accepts: text/html instead of text/javascript. Flushing that cache loaded the newer version of prototype and fixed the problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T07:08:10+00:00Added an answer on June 1, 2026 at 7:08 am

    It turns out that we had a before_filter that was being run before every request setting the content-type to text/html. I removed that, and it worked without the hack below.

    But if you need a workaround, here’s what I did below.

    The only thing I figure out to make this work was to add headers["Content-Type"] = "text/javascript; charset=utf-8" before the render :update

    headers["Content-Type"] = "text/javascript; charset=utf-8"
    render :update do |page|
      if @step.errors.empty?
        page.redirect_to how_to_path(@article.id)
      else
        page.replace_html 'add_step_form', :partial => 'how_to/add_step', :locals => {:step => @step, :altered => true}
      end
    end
    

    Unfortunately, I’ve had to add it in every place in the code where the RJS render :update is called.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.