[Ruby] evaluating Javascript within <%= %> within a template file

James Hillyerd james at hillyerd.com
Tue Aug 7 12:15:01 PDT 2007


On 8/7/07, Frank Schwieterman <fschwiet at gmail.com> wrote:
>
>   Hmm alright.  It turns out that when I use '<%= url_for :action =>
> "thing", :id => "' + id_to_use + '"%>', the '+' and the quotes are escaped
> in the resulting HTML/Javascript.  So it doesn't work...
>
>   I guess my options are to either hardcode the url, or put in a string I
> can replace later with a regex.  It seems the later is safer in case the
> url_for behavior changes... I doubt that would happen though.


If it's a simple URL, I tend to use a pattern like:

var url = '<%= url_for :action => 'edit' %>/' + id_to_edit;

-james

-- 
James A. Hillyerd <james at hillyerd.com>
Chief Technical Officer - ActiveRain Corp


More information about the Ruby mailing list