James Whittaker
2006-Apr-13 10:49 UTC
[Rails] Why won''t this work - simple helper text ??
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 ???? -- Posted via http://www.ruby-forum.com/.
James Whittaker wrote:> 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 ???? >''<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. -- Alex
James Whittaker
2006-Apr-13 11:39 UTC
[Rails] Re: Why won''t this work - simple helper text ??
Alex Young wrote:> James Whittaker 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. -- Posted via http://www.ruby-forum.com/.
Trevor Squires
2006-Apr-13 12:57 UTC
[Rails] Re: Why won''t this work - simple helper text ??
On 13-Apr-06, at 4:39 AM, James Whittaker wrote:> Alex Young wrote: >> James Whittaker 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. >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 Squires http://somethinglearned.com