Forum: Ruby on Rails Why won't this work - simple helper text ??

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
James W. (Guest)
on 2006-04-13 14:49
Trying to print this out and it fails,

def cancel_toggle(element)
  '<a href="#" onclick="new Effect.toggle("' + element + '","blind",
{duration: 0.4}); return false;" >Add a New Client</a>'
end

When called in my view like this:
<%= cancel_toggle "newClient" %>

It gets written to the browser but does not work. When placed directly
in the view it works. Firefox highlights the following in red (in source
view):

newClient","blind"

It must be something to do with my quotes but I cannot see it. Help
please ????
Alex Y. (Guest)
on 2006-04-13 15:06
(Received via mailing list)
James W. wrote:
> It gets written to the browser but does not work. When placed directly
> in the view it works. Firefox highlights the following in red (in source
> view):
>
> newClient","blind"
>
> It must be something to do with my quotes but I cannot see it. Help
> please ????
>
'<a href="#" onclick="new Effect.toggle(\'' + element + '\',\'blind\',
  {duration: 0.4}); return false;" >Add a New Client</a>'

should work.  You had the same quote around the onclick attribute as
around the javascript strings.
James W. (Guest)
on 2006-04-13 15:39
Alex Y. wrote:
> James W. wrote:
>> It gets written to the browser but does not work. When placed directly
>> in the view it works. Firefox highlights the following in red (in source
>> view):
>>
>> newClient","blind"
>>
>> It must be something to do with my quotes but I cannot see it. Help
>> please ????
>>
> '<a href="#" onclick="new Effect.toggle(\'' + element + '\',\'blind\',
>   {duration: 0.4}); return false;" >Add a New Client</a>'
>
> should work.  You had the same quote around the onclick attribute as
> around the javascript strings.

Thanks, I actually got it to work using this:

 "<a href=\"#\" class =\"redLink\" onclick=\"new
Effect.toggle('#{element}','blind', {duration: 0.4}); return false;\"
>cancel</a>"

Your looks a little neater though. Thanks again.
Trevor S. (Guest)
on 2006-04-13 17:00
(Received via mailing list)
On 13-Apr-06, at 4:39 AM, James W. wrote:

>>> It must be something to do with my quotes but I cannot see it. Help
>
>  "<a href=\"#\" class =\"redLink\" onclick=\"new
> Effect.toggle('#{element}','blind', {duration: 0.4}); return false;\"
>> cancel</a>"
>
> Your looks a little neater though. Thanks again.
>

Hi James,

If you're willing to put up with extra noise at the beginning of your
string you can get rid of the backslashes.  This string is equivalent
to yours:

%Q|<a href="#" class ="redLink" onclick="new Effect.toggle('#
{element}','blind', {duration: 0.4}); return false;">cancel</a>|

... and in case it gets mangled in the mail, it's percent Q pipe at
the start of the string and pipe at the end.

Regards,
Trevor
--
Trevor S.
http://somethinglearned.com
This topic is locked and can not be replied to.