On Tue, Feb 22, 2011 at 2:53 PM, Niklas Nson <[email protected]> wrote:

> Trying to follow railscast #88, i know the js.erb file is loaded but
> when i try to insert ruby code in the .js.erb file i get an error
> "illegal XML character" i have added the following line to my routes
> file
> match ":controller(/:action(/:id(.:format)))"
>
> and code not working is:
>
> ...
>
>        var states = new Array();
>        <% for state in @states -%>
>        states.push(new Array(<%= state.country_id %>, '<%=h state.name%>', <
> %= state.id %>));
>        <% end -%>
> ...
>
>
could you try

var states = <%= @states.collect {|state| [state.country_id,
h(state.name)]}.to_json
%>


> I have spent hours on trying to solve, could someone point me to the
> answer ?
>
> if i remove ruby code and do states.push(new Array(1, 'test', 1)); it
> works like i want, but i need Array to contain vales from my
> JavascriptsController
>
> //Niklas.
>
> --
> 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 [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>


-- 
-------------------------------------------------------------
visit my blog at http://jimlabs.heroku.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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to