How can I make this work ? <a href="#" onclick="new Effect.Fade(@div_id)"></a> @div_id is an instance variable ? TIA -- Posted via http://www.ruby-forum.com/.
nuubie wrote:> How can I make this work ? > > <a href="#" onclick="new Effect.Fade(@div_id)"></a> > > @div_id is an instance variable ? > > TIA >The @div_id needs to be encapsulated in <%= %> tags in order to be parsed by ruby. i.e. <a href="#" onclick="new Effect.Fade(<%= @div_id %>)"></a> It is probably preferable to use the built-in rails helpers for this though. Try: <%= link_to_function ''Link text'', visual_effect(:fade, @div_id) %> -Sam
or use the tag helper:
<%= content_tag "a", "link-text", {:href =>
"#", :onclick => "new
Effect.Fade(#{div_id})"} %>
> --- Urspr?ngliche Nachricht ---
> Von: Sam Pohlenz <retrix@internode.on.net>
> An: rails@lists.rubyonrails.org
> Betreff: Re: [Rails] Instance variables in Javascript param
> Datum: Thu, 02 Mar 2006 18:57:49 +1030
>
> nuubie wrote:
> > How can I make this work ?
> >
> > <a href="#" onclick="new
Effect.Fade(@div_id)"></a>
> >
> > @div_id is an instance variable ?
> >
> > TIA
> >
>
> The @div_id needs to be encapsulated in <%= %> tags in order to be
> parsed by ruby. i.e.
> <a href="#" onclick="new Effect.Fade(<%= @div_id
%>)"></a>
>
> It is probably preferable to use the built-in rails helpers for this
> though. Try:
> <%= link_to_function ''Link text'', visual_effect(:fade,
@div_id) %>
>
> -Sam
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
another possible one:
link_to("link-text", {}, {:onclick => "new
Effect.Fade(#{div_id})"} )
[did not test that...]
> --- Urspr?ngliche Nachricht ---
> Von: Sam Pohlenz <retrix@internode.on.net>
> An: rails@lists.rubyonrails.org
> Betreff: Re: [Rails] Instance variables in Javascript param
> Datum: Thu, 02 Mar 2006 18:57:49 +1030
>
> nuubie wrote:
> > How can I make this work ?
> >
> > <a href="#" onclick="new
Effect.Fade(@div_id)"></a>
> >
> > @div_id is an instance variable ?
> >
> > TIA
> >
>
> The @div_id needs to be encapsulated in <%= %> tags in order to be
> parsed by ruby. i.e.
> <a href="#" onclick="new Effect.Fade(<%= @div_id
%>)"></a>
>
> It is probably preferable to use the built-in rails helpers for this
> though. Try:
> <%= link_to_function ''Link text'', visual_effect(:fade,
@div_id) %>
>
> -Sam
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
Wow, this is a great list. Real-time response.... Thanks a lot, guys. Peter Ertl wrote:> another possible one: > > link_to("link-text", {}, {:onclick => "new Effect.Fade(#{div_id})"} ) > > [did not test that...]-- Posted via http://www.ruby-forum.com/.