Forum: Ruby on Rails javascript rendered as text: why?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
ruud (Guest)
on 2014-03-18 16:12
(Received via mailing list)

in order to add some ajax-calls to a site, I did a little test. The
is that the result of the javascript is rendered as text.

I use rails 3.1.12

In the view that contains a test link to trigger the javascript I have

    <td><%= link_to factuur.nummer, toon_facturen_path( :id =>,
                                            :format => :js,
                                            :remote => true) %></td>

In the I have

    def toon
        logger.error( "toon....")
        @factuur = Factuur.find(params[:id])
        respond_to do |format|
            format.js   # toon.js.rjs

The layout file starts with

<!DOCTYPE html>
  <title>brieven- en facturenarchief</title>
  <%= stylesheet_link_tag    "application" %>
  <%= javascript_include_tag :application %>
  <%= csrf_meta_tags %>

The rjs-file toon.js.rjs contains a simple test statement:

page.replace_html( 'status', '<p>test</p>')

When I follow the link, the following is rendered on the screen:

Element.update("status", "<p>test</p>");

(which isn't exact the contents of the rjs) and the server says
Started GET "/facturen/toon.js?id=1&remote=true" for at Tue
18 14:30:43 +0100 2014
  Processing by FacturenController#toon as JS
  Parameters: {"id"=>"1", "remote"=>"true"}
  Factuur Load (1.0ms)  SELECT "facturen".* FROM "facturen" WHERE
"facturen"."id" = 1 LIMIT 1

Rendered facturen/toon.js.rjs (4.0ms)
Completed 200 OK in 92ms (Views: 51.0ms | ActiveRecord: 1.0ms)

However, the resulting page shows the text of toon.js.rjs in

In addition I can mention config/application.rb requires prototype-rails
and app/assets/application.js contains the lines

//= require prototype
//= require prototype_ujs
//= require effects
//= require dragdrop
//= require controls

I am out of ideas. Can somebody help me out of this?

thanks in advance, Ruud
ruud (Guest)
on 2014-03-20 11:53
(Received via mailing list)
It is because of a misplaced right parenthisis. De resulting link from
link_to was like
<a href="....?remote=true">......
and no data-remote attribute was given.

<%= link_to factuur.nummer, toon_facturen_path( :id =>,
                                            :format => :js,
                                            :remote => true*)* %></td>

should have been
<%= link_to factuur.nummer, toon_facturen_path( :id =>,
                                            :format => :js*)*,
                                            :remote => true %></td>

Thank you all for your time, Ruud
This topic is locked and can not be replied to.