RJS - unterminated string literal

Hi guys,

I’m having problems with RJS, and can’t figure it out… I’m using RJS
to do a very simple effect on a div:

page.visual_effect :blind_up, ‘comment-’[email protected]

The request works, but the javascript it sends to the browser doesn’t
work:

try {

new Effect.BlindUp(“comment-9”,{});

} catch (e) { alert(‘RJS error:\n\n’ + e.toString()); alert('new
Effect.BlindUp(“comment-9”,{

});’); throw e }

The new lines inside the code end up causing an “unterminated string
literal” error on the browser… If i remove them manually, it works
correctly.

Do you guys have any idea??

Thanks!!

What about

page[‘comment’[email protected]].visual_effect :blind_up

On Aug 10, 5:19 am, Eduardo S. [email protected]

nigel.bris wrote:

What about

page[‘comment’[email protected]].visual_effect :blind_up

On Aug 10, 5:19 am, Eduardo S. [email protected]

Hi Nigel,

Thanks for the reply. Unfortunately, it didn’t work… It generated the
same javascript, with the extra line breaks…

Thanks, Nigel,

I’ll give it a try soon, and let you know.

I’m using a compacted scriptaculous library instead of the default ones,
but it work fine… the problem was really with the spaces… fixing them
manually on firebug was making it work.

Thanks a lot!

Eduardo

I realise now, my code should not of worked (unless @id is already a
string) so it should be @id.to_s… But this this not the issue
because your code shows the “comment-9”

Do you have javascript_include_tag :defaults ?

Here is my test (which works), otherwise use firefox and firebug to
debug

Hope this helps

index.rhtml

<%=javascript_include_tag :defaults %>
a
<%=link_to_remote "press me", :url=>{:action=>:hide_me} %>

hide_me.rjs
@id=1
page['comment-'[email protected]_s].visual_effect :blind_up

On Aug 11, 12:28 am, Eduardo S. [email protected]

Hi Axel!

I haven’t still been able to figure out that problem… I ended up
working on some other things, hoping somebody would know the solution…
:slight_smile:

Well, at least I’m not the only one with the problem now. I’ll try to
trace the rails code to find out where this problem is being created.
I’ll post an update here if I find out anything.

Please let me know if you find anything as well!

Regards

Eduard

Did you try using <%= -%> instead of <%= %> ? (the dash-percent-
greaterthan is supposed to not spit out an additional #\linefeed).

Paul H. wrote:

Did you try using <%= -%> instead of <%= %> ? (the dash-percent-
greaterthan is supposed to not spit out an additional #\linefeed).

I tried your idea (sounded reasonable), but it still didn’t work. And
I’m slowly running out of other ideas. I think I’m gonna lay this thing
aside for some days and try it again in a week. Perhaps I got some fresh
ideas by then.
Nevertheless, thanks for your help! I let you know, as soon as I find
anything out.

Bye
Axel

Eduardo S. wrote:

Thanks, Nigel,

I’ll give it a try soon, and let you know.

I’m using a compacted scriptaculous library instead of the default ones,
but it work fine… the problem was really with the spaces… fixing them
manually on firebug was making it work.

Thanks a lot!

Eduardo

Hi there,

I have the exact same problem. I’m using a RJS for creating a new li
element. This happens with a partial.

create.rjs
page.insert_html :bottom, ‘playlist’, :partial =>
‘songs/song_listing’, :locals => {:song => @song}

song_listing partial

  • <%=h song.artist%> - <%=h song.name%> <%if logged_in?%>(<%=link_to_remote "Remove".t, :url => { :controller => "playlists", :action => "destroy_song", :id => song.id }, :confirm => 'Are you sure you want to delete this song?'.t %>)<% end %>
  • This partial doesn’t have any unnecessary spaces or line breaks! But
    what I get in Firebug is the following (including the line breaks!):

    new Insertion.Bottom(“playlist”, “<li id=“song_100”>TestArtist -
    TestName (<a href=”#" onclick="if

    (confirm(‘Are you sure you want to delete this song?’)) { new
    Ajax.Request(’/en/playlists/destroy_song

    /100’, {asynchronous:true, evalScripts:true}); }; return
    false;">Remove)");

    As soon as I remove the line breaks, everything is executed just fine.
    I’m sitting at this problem for some time now. The whole thing worked
    for some time. I added a similar functionality to a different section on
    my site and both stopped working. I double-checked everything and can’t
    see any problems.

    Did you solved the problem yet? Any suggestions or tips for my case?

    Bye
    Axel

    Eduardo S. wrote:

    try {
    literal" error on the browser… If i remove them manually, it works
    correctly.

    There used to be a bug in the RJS JavaScript debugging code, but it
    was fixed some time ago. Are you using actionpack-1.13.3?

    Alternatively, turn off the debug code by adding

    config.action_view.debug_rjs = false

    inside the Rails::Initializer.run block in environment.rb.


    We develop, watch us RoR, in numbers too big to ignore.

    hi everybody,

    just for the record, I ended up finding out what the problem was.

    I had added a function to the application.rb to include headers on every
    request to set the proper response content-type and content-language.

    The problem is that those two things were being added to every
    request, even JS ones. That was causing the problem.

    After commenting out those two lines, everything is working again.

    Thanks for everybody!

    Eduardo

    Hi Mark!

    thanks for the reply… Unfortunately, it’s still not working. I’m using
    Actionpack-1.13.3.

    I tried the “debug_rjs = false”, but I still get the exact same JS as
    the output.

    In regard to the previous post, about using <%= -%>, I’m not even using
    those tags, I just have the page[‘a’].visual_effect command directly on
    the RJS file.

    Thanks a lot for the help so far, everybody…

    Mark Reginald J. wrote:

    Eduardo S. wrote:

    try {
    literal" error on the browser… If i remove them manually, it works
    correctly.

    There used to be a bug in the RJS JavaScript debugging code, but it
    was fixed some time ago. Are you using actionpack-1.13.3?

    Alternatively, turn off the debug code by adding

    config.action_view.debug_rjs = false

    inside the Rails::Initializer.run block in environment.rb.


    We develop, watch us RoR, in numbers too big to ignore.

    Great to know it worked for you as well, Axel!

    Thanks for the link.

    Axel Benjamins wrote:

    Hi Eduardo,

    thanks very much. I had the same problem. After some googling I found
    the following:
    http://nubyonrails.com/articles/rjs-and-content-type-header (see the
    section labeled “Content-Type Header”)

    Just use a before_filter instead of an after_filter. The content-type
    will only be set, whenever a template is rendered, which needs a
    content-type. RJS templates will be ignored and rendered correctly.

    Again, big thanks for posting the solution. Would have searched another
    month for this…

    Bye
    Axel

    Hi Eduardo,

    thanks very much. I had the same problem. After some googling I found
    the following:
    http://nubyonrails.com/articles/rjs-and-content-type-header (see the
    section labeled “Content-Type Header”)

    Just use a before_filter instead of an after_filter. The content-type
    will only be set, whenever a template is rendered, which needs a
    content-type. RJS templates will be ignored and rendered correctly.

    Again, big thanks for posting the solution. Would have searched another
    month for this…

    Bye
    Axel

    Eduardo S. wrote:

    hi everybody,

    just for the record, I ended up finding out what the problem was.

    I had added a function to the application.rb to include headers on every
    request to set the proper response content-type and content-language.

    The problem is that those two things were being added to every
    request, even JS ones. That was causing the problem.

    After commenting out those two lines, everything is working again.

    Thanks for everybody!

    Eduardo

    This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

    | Privacy Policy | Terms of Service | Remote Ruby Jobs