Tuesday, February 22, 2011

[Rails] Re: Can't get .js.erb to work ...

That gives me the error (in firebug)

illegal XML character
[Stop on error] var states = <%= @states.collect {|st...ountry_id,
h(state.name)]}.to_json %>

On 22 Feb, 08:22, Jim Ruther Nill <jvn...@gmail.com> wrote:
> On Tue, Feb 22, 2011 at 2:53 PM, Niklas Nson <niklasn...@meantime.se> 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 rubyonrails-talk@googlegroups.com.
> > To unsubscribe from this group, send email to
> > rubyonrails-talk+unsubscribe@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/rubyonrails-talk?hl=en.
>
> --
> -------------------------------------------------------------
> visit my blog athttp://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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate