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

35fee05a52be6486f619d56fa42341ac?d=identicon&s=25 ruud (Guest)
on 2014-03-18 16:12
(Received via mailing list)
hello,

in order to add some ajax-calls to a site, I did a little test. The
problem
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 =>
factuur.id,
                                            :format => :js,
                                            :remote => true) %></td>

In the FacturenController.pm I have

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

The layout file starts with

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

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 127.0.0.1 at Tue
Mar
18 14:30:43 +0100 2014
  Processing by FacturenController#toon as JS
  Parameters: {"id"=>"1", "remote"=>"true"}
toon....
  Factuur Load (1.0ms)  SELECT "facturen".* FROM "facturen" WHERE
"facturen"."id" = 1 LIMIT 1
respond_to....

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
HTML-pre-tags

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
35fee05a52be6486f619d56fa42341ac?d=identicon&s=25 ruud (Guest)
on 2014-03-20 11:53
(Received via mailing list)
It is because of a misplaced right parenthisis. De resulting link from
the
link_to was like
<a href="....?remote=true">......
and no data-remote attribute was given.

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

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

Thank you all for your time, Ruud
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.