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

Frank Schwieterman fschwiet at gmail.com
Tue Aug 7 01:10:21 PDT 2007


  Are you sure about that?  I can't get it to work.

  One issue I see is that the <% %> enclosure is evaluated when the website
is served, but "id_to_use" will not have a value until the Javascript is
ran.  I don't see any way for a <% %> enclosure to take a parameter.  Maybe
this is just not possible...


On 8/6/07, Jack Danger Canty <seattle.rb at 6brand.com> wrote:
>
> You want this:
> function whats_the_url(id_to_use)
> {
>    var url = '<%= url_for(:action=> 'edit', :id => "'+id_to_use+'") %>';
>
>    return url;
> }
>
> ::Jack Danger Canty
>
> On 8/6/07, Frank Schwieterman <fschwiet at gmail.com> wrote:
> >
> >   I'm in a situation where I have some Javascript and am using <%=
> > url_for()
> > %> to generate a value within the JavaScript.  One of the parameters for
> > url_for however is coming from a Javascript variable, I'm not sure how
> to
> > do
> > it.  I've written the below function trying to imitate my problem-
> > variable
> > "id_to_use" is not valid within an <%= ... %> enclosure.
> >
> > function whats_the_url(id_to_use)
> > {
> >     var url = <%= url_for(:action=> 'edit', :id => id_to_use) %>;
> >
> >     return url;
> > }
> > _______________________________________________
> > Ruby at zenspider.com - Seattle.rb non-commercial list
> > http://www.zenspider.com/seattle.rb
> > http://www.zenspider.com/mailman/listinfo/ruby
> >
> _______________________________________________
> Ruby at zenspider.com - Seattle.rb non-commercial list
> http://www.zenspider.com/seattle.rb
> http://www.zenspider.com/mailman/listinfo/ruby
>


More information about the Ruby mailing list