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

  • Home
  • SEARCH
  • 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 4079890
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:51:35+00:00 2026-05-20T17:51:35+00:00

I’m having a trouble with rails3 to render Javascript (If this is relevant, I

  • 0

I’m having a trouble with rails3 to render Javascript (If this is relevant, I use JQuery and it works fine since it’s used in numerous other parts of the application) instead of html.

What I have:
I a view, I have this link:

<%= link_to 'Edit', edit_user_repreneur_path(@user_repreneur, :format => :js), :remote => true %>

First of all, I don’t really get why I have to add :format => :js to get the controller to use the JS view, and not the HTML one.
Here is the code of the controller:

def edit
    @user_repreneur = UserRepreneur.find_by_id_view(params[:id])
    respond_to do |format|
      format.js
      format.html
    end 
end

At the beginning of the controller class, I have this line:

  respond_to :js, :html

My edit.js.erb file contains a single line with an alert.
However, when rendering the page, the JS is rendered as text, and therefore is not executed.
I tried to change the format.js line to

format.js { render :layout => false }

But it doesn’t change anything.
I guess I am missing something, but I really don’t see what…

Thanks a lot in advance, cheers!

PS: I don’t know if this is helpful, but before I add the :format => :js bit in my link helper, the view was always rendered as HTML, and if I commented the format.html line, I had a 406 Not Acceptable error on the server side.

  • 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-05-20T17:51:35+00:00Added an answer on May 20, 2026 at 5:51 pm

    I don’t think the problem is with your server-side code. It all looks good to me. And the fact that it is rendering edit.js.erb proves that your server-side code is working fine.

    The problem is on your client-side. When it receives the Ajax response, it isn’t executing it as javascript. It is executing it as text.

    I have recently had this problem myself and I wish I had my code with me but I’m at work. However, I personally wrote the jQuery Ajax request instead of relying on :remote => true since that option is mostly used in forms.

    Try giving your link_to an id and then put this jQuery in your application.js or wherever.

    $('#link_id').click(function(){
       $.ajax({
          type : 'GET',
          url : '/:controller/:action/',
          dataType : 'script'
       });
       return false;
    });
    

    This will grab the link’s click event, send a request to the server which should return your edit.js.erb file, and then execute it as script.

    Mind you, there is a lot of security concerns to take into account as well as authenticity tokens and the like. However, this should get your alert to execute and get you on the right path to completing your app.

    Read up on jQuery’s Ajax for further options and details about POSTing data as well.

    Hope this helps.

    UPDATE: Other possible solutions include using UJS as a Javascript driver. You can read the documentation at https://github.com/rails/jquery-ujs and view a Railscast on the topic Unobtrusive Javascript using UJS.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.