I am doing an Ajax call, rendering ''done.js.erb'' in which I
wrote a
jQuery append built from an helper current_snippet
$(''#upload_tables'').append("<%=
current_snippet(@remote_locker,
@current) -%>"); RAISES AN ERROR : missing ) after argument
list
--- debugging the current_snippet helper, I get an html string as
output
"<tr id=''table_instructors''><td><img
alt=''Ajax-loader'' height=''16''
src=''/images/ajax-loader.gif'' width=''16''
/></td><td>table_instructors</
td><td><a
href=\"/en/admin/remote_lockers/4d7b27b8a326cb033d00000b/
reloading.js?table=table_instructors\"
data-remote=\"true\">start</a></
td></tr>"
-- but strange ... if I copy this string into the js file (rather than
calling the snippet helper) then NO ERROR ...
$(''#upload_tables'').append("<tr
id=''table_instructors''><td><img
alt=''Ajax-loader'' height=''16''
src=''/images/ajax-loader.gif''
width=''16''
/></td><td>table_instructors</td><td><a
href=\"/en/admin/
remote_lockers/4d7b27b8a326cb033d00000b/reloading.js?
table=table_instructors\"
data-remote=\"true\">start</a></td></tr>");
so the output string is well escaped ... why plain string is working
well , but helper call is not ...
I already used another snippet helper in a previous js line without
such problem....
$(''#<%= @previous -%>'').replaceWith("<%=
previous_snippet(@previous) -
%>");
so it''s not the js line writing....
if I insert a simple link tag in the helper, rather than generating
it , ( html << "<a
href=''#''>Start</a>" ) then
$(''#upload_tables'').append("<%=
current_snippet(@remote_locker,
@current) -%>"); doesn"t raise ANY ERROR
"<tr id=''table_instructors''><td><img
alt=''Ajax-loader'' height=''16''
src=''/images/ajax-loader.gif'' width=''16''
/></td><td>table_instructors</
td><td><a
href=''#''>Start</a></td></tr>"
it seems the ''issue'' is in the link_to generated in the helper
link_to I18n.t(:start),
reloading_admin_remote_locker_path(remote_locker, :table =>
current, :format => :js), :remote => true
any clue ? thanks
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
On 14 Mar 2011, at 17:46, Erwin <yves_dufour-ee4meeAH724@public.gmane.org> wrote:> I am doing an Ajax call, rendering ''done.js.erb'' in which I wrote a > jQuery append built from an helper current_snippet > > $(''#upload_tables'').append("<%= current_snippet(@remote_locker, > @current) -%>"); RAISES AN ERROR : missing ) after argument > listYou''re not escaping the output of current snippet - if it contains any " then that will screw up stuff If you inspect the output of current_snippet the it will print " characters as \" but that''s just how it displays stuff - it doesn''t mean that any escaping has actually taken place. There''s an escape_javascript (or something similarly named) method in rails Fred> > --- debugging the current_snippet helper, I get an html string as > output > > "<tr id=''table_instructors''><td><img alt=''Ajax-loader'' height=''16'' > src=''/images/ajax-loader.gif'' width=''16'' /></td><td>table_instructors</ > td><td><a href=\"/en/admin/remote_lockers/4d7b27b8a326cb033d00000b/ > reloading.js?table=table_instructors\" data-remote=\"true\">start</a></ > td></tr>" > > -- but strange ... if I copy this string into the js file (rather than > calling the snippet helper) then NO ERROR ... > > $(''#upload_tables'').append("<tr id=''table_instructors''><td><img > alt=''Ajax-loader'' height=''16'' src=''/images/ajax-loader.gif'' > width=''16'' /></td><td>table_instructors</td><td><a href=\"/en/admin/ > remote_lockers/4d7b27b8a326cb033d00000b/reloading.js? > table=table_instructors\" data-remote=\"true\">start</a></td></tr>"); > > so the output string is well escaped ... why plain string is working > well , but helper call is not ... > I already used another snippet helper in a previous js line without > such problem.... > $(''#<%= @previous -%>'').replaceWith("<%= previous_snippet(@previous) - > %>"); > so it''s not the js line writing.... > > if I insert a simple link tag in the helper, rather than generating > it , ( html << "<a href=''#''>Start</a>" ) then > $(''#upload_tables'').append("<%= current_snippet(@remote_locker, > @current) -%>"); doesn"t raise ANY ERROR > > "<tr id=''table_instructors''><td><img alt=''Ajax-loader'' height=''16'' > src=''/images/ajax-loader.gif'' width=''16'' /></td><td>table_instructors</ > td><td><a href=''#''>Start</a></td></tr>" > > it seems the ''issue'' is in the link_to generated in the helper > link_to I18n.t(:start), > reloading_admin_remote_locker_path(remote_locker, :table => > current, :format => :js), :remote => true > > any clue ? thanks > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
[SOLVED] after playing with the snippet generation , I finally
resolved to modify the way the link_to was generated
by writing myself the link tag ....
path = reloading_admin_remote_locker_path(remote_locker, :table =>
current, :format => :js)
html << ''<a href='' + "#{path}
data-remote=''true''>#{I18n.t(:start)}
</a></td></tr>"
I can even write it in one line... but I''ll have a look at the
escape_javascript as suggested.... thanks a lot
On 14 mar, 19:01, Frederick Cheung
<frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> On 14 Mar 2011, at 17:46, Erwin
<yves_duf...-ee4meeAH724@public.gmane.org> wrote:
>
> > I am doing an Ajax call, rendering ''done.js.erb'' in
which I wrote a
> > jQuery append built from an helper current_snippet
>
> > $(''#upload_tables'').append("<%=
current_snippet(@remote_locker,
> > @current) -%>"); RAISES AN ERROR : missing ) after
argument
> > list
>
> You''re not escaping the output of current snippet - if it contains
any " then that will screw up stuff
>
> If you inspect the output of current_snippet the it will print "
characters as \" but that''s just how it displays stuff - it
doesn''t mean that any escaping has actually taken place.
There''s an escape_javascript (or something similarly named) method in
rails
>
> Fred
>
>
>
>
>
>
>
>
>
> > --- debugging the current_snippet helper, I get an html string as
> > output
>
> > "<tr
id=''table_instructors''><td><img
alt=''Ajax-loader'' height=''16''
> > src=''/images/ajax-loader.gif''
width=''16'' /></td><td>table_instructors</
> > td><td><a
href=\"/en/admin/remote_lockers/4d7b27b8a326cb033d00000b/
> > reloading.js?table=table_instructors\"
data-remote=\"true\">start</a></
> > td></tr>"
>
> > -- but strange ... if I copy this string into the js file (rather than
> > calling the snippet helper) then NO ERROR ...
>
> > $(''#upload_tables'').append("<tr
id=''table_instructors''><td><img
> > alt=''Ajax-loader'' height=''16''
src=''/images/ajax-loader.gif''
> > width=''16''
/></td><td>table_instructors</td><td><a
href=\"/en/admin/
> > remote_lockers/4d7b27b8a326cb033d00000b/reloading.js?
> > table=table_instructors\"
data-remote=\"true\">start</a></td></tr>");
>
> > so the output string is well escaped ... why plain string is working
> > well , but helper call is not ...
> > I already used another snippet helper in a previous js line without
> > such problem....
> > $(''#<%= @previous
-%>'').replaceWith("<%= previous_snippet(@previous) -
> > %>");
> > so it''s not the js line writing....
>
> > if I insert a simple link tag in the helper, rather than generating
> > it , ( html << "<a
href=''#''>Start</a>" ) then
> > $(''#upload_tables'').append("<%=
current_snippet(@remote_locker,
> > @current) -%>"); doesn"t raise ANY ERROR
>
> > "<tr
id=''table_instructors''><td><img
alt=''Ajax-loader'' height=''16''
> > src=''/images/ajax-loader.gif''
width=''16'' /></td><td>table_instructors</
> > td><td><a
href=''#''>Start</a></td></tr>"
>
> > it seems the ''issue'' is in the link_to generated in
the helper
> > link_to I18n.t(:start),
> > reloading_admin_remote_locker_path(remote_locker, :table =>
> > current, :format => :js), :remote => true
>
> > any clue ? thanks
>
> > --
> > You received this message because you are subscribed to the Google
Groups "Ruby on Rails: Talk" group.
> > To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > For more options, visit this group
athttp://groups.google.com/group/rubyonrails-talk?hl=en.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.