Are you using the GeoKit Rails plugin?

On Jul 23, 3:52 am, Max Williams <rails-mailing-l...@andreas-s.net>
wrote:
> vlain wrote:
> > Wrap variables around <%= %> inside double quote
> > e.g.
> > for(var j=0; j < "<%=locations.length%>"; j++)
>
> > On Jul 22, 4:17 pm, Nilesh Kulkarni <rails-mailing-l...@andreas-s.net>
>
> As a slightly more general solution, rather than wrapping the "" around
> the erb block, if you call inspect on the object inside then it will
> have quotes added if it's a string but not if it's a number, and if it's
> an array it will be shown in the right format, etc.  So, .inspect makes
> things print out in such a way that they 'look right' and can be used as
> is.
>
> (In the example above it looks like you need a number rather than a
> string. )
>
> #in rails controller
> @cars = Car.find(:all)
>
> #in your js section in a view page
> var carNames = <%= @cars.collect(&:name).inspect %>;
> => var carNames = ["Micra", "Primera", "Almeira"];
>
> var firstCarModel = <%= @cars.first.model.inspect %>;
> => var firstCarModel = "Nissan";
>
> for(var j=0; j < <%= @cars.length.inspect %>; j++)
> => for(var j=0; j < 3; j++)
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to