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 -%> ... 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Tue, Feb 22, 2011 at 2:53 PM, Niklas Nson <niklasnson-5ZBJkHaGu7EwFerOooGFRg@public.gmane.org> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> On Tue, Feb 22, 2011 at 2:53 PM, Niklas Nson
<niklasn...-5ZBJkHaGu7EwFerOooGFRg@public.gmane.org> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > To unsubscribe from this group, send email to
> >
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
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.
On Tue, Feb 22, 2011 at 4:05 PM, Niklas Nson <niklasnson-5ZBJkHaGu7EwFerOooGFRg@public.gmane.org> wrote:> 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 %> > >what''s the generated js code by that template? is it a valid js array?> On 22 Feb, 08:22, Jim Ruther Nill <jvn...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > On Tue, Feb 22, 2011 at 2:53 PM, Niklas Nson <niklasn...-5ZBJkHaGu7EwFerOooGFRg@public.gmane.org> > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > > > To unsubscribe from this group, send email to > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Tue, Feb 22, 2011 at 12:05 AM, Niklas Nson <niklasnson-5ZBJkHaGu7EwFerOooGFRg@public.gmane.org> wrote:> 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 %>If that''s what the client is seeing, it would seem to indicate that your *.js.erb file is not actually being evaluated. Is there anything (errors) in your logs to indicate why that might be? -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Yes i also belive that it dosent fire up. If i go to :
http://localhost:3000/javascripts/location_handler.js
i get a - No route matches "/javascripts/location_handler.js" - error
if i go to http://localhost:3000/javascripts/location_handler.js.erb i
see the complete source
---
function countrySelected() {
country_id = $(''account_country'').getValue();
var states = <%= @states.collect {|state| [state.country_id,
h(state.name)]}.to_json %>
<% for state in @states -%>
states.push(new Array(<%= state.country_id %>, ''<%=h
state.name %>'', <
%= state.id %>));
<% end -%>
options = $(''account_state'').options;
options.length = 1;
states.each(function(state) {
if (state[0] == country_id) {
options[options.length] = new Option(state[1], state[2]);
}
});
}
---
In my routes file i have added
match ":controller(/:action(/:id(.:format)))"
Do i need to do some other configs ?
On 22 Feb, 16:47, Hassan Schroeder
<hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> On Tue, Feb 22, 2011 at 12:05 AM, Niklas Nson
<niklasn...-5ZBJkHaGu7EwFerOooGFRg@public.gmane.org> wrote:
> > 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 %>
>
> If that''s what the client is seeing, it would seem to indicate
that your
> *.js.erb file is not actually being evaluated.
>
> Is there anything (errors) in your logs to indicate why that might be?
>
> --
> Hassan Schroeder ------------------------
hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
> twitter: @hassan
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
[Hope this wont be a dubbel post]
My feeling is also that it dosent fire the ruby part of the script.
If i go to http://localhost:3000/javascripts/location_handler.js i
get
a No route matches "/javascripts/location_handler.js" error.
If i go to http://localhost:3000/javascripts/location_handler.js.erb i
see the
source code
...
function countrySelected() {
country_id = $(''account_country'').getValue();
var states = <%= @states.collect {|state| [state.country_id,
h(state.name)]}.to_json %>
<% for state in @states -%>
states.push(new Array(<%= state.country_id %>, ''<%=h
state.name %>'', <
%= state.id %>));
<% end -%>
options = $(''account_state'').options;
options.length = 1;
states.each(function(state) {
if (state[0] == country_id) {
options[options.length] = new Option(state[1], state[2]);
}
});
}
function stateSelected() {
options = $(''account_city'').options;
options.length = 1;
}
...
I have added match ":controller(/:action(/:id(.:format)))" to my
routes.rb is there anything else i need to do ?
//Niklas
On 22 Feb, 16:47, Hassan Schroeder
<hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> On Tue, Feb 22, 2011 at 12:05 AM, Niklas Nson
<niklasn...-5ZBJkHaGu7EwFerOooGFRg@public.gmane.org> wrote:
> > 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 %>
>
> If that''s what the client is seeing, it would seem to indicate
that your
> *.js.erb file is not actually being evaluated.
>
> Is there anything (errors) in your logs to indicate why that might be?
>
> --
> Hassan Schroeder ------------------------
hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
> twitter: @hassan
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
On Tue, Feb 22, 2011 at 10:51 AM, Niklas Nson <niklasnson-5ZBJkHaGu7EwFerOooGFRg@public.gmane.org> wrote:> Yes i also belive that it dosent fire up. If i go to : > http://localhost:3000/javascripts/location_handler.jsOops. That''s the problem -- files under public are static, that is, *not* interpreted. You need to put your file somewhere within app/views. -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
:)
I moved the file to /views/javascripts/getlocation.js.erb
But there must be something wrong with routes or something else
still.
If i go to: http://localhost:3000/javascripts/getlocation.js i get a
No route matches "/javascripts/getlocation.js" error.
[Routes]
ModcubeApp::Application.routes.draw do
get "log_in" => "sessions#new", :as =>
"log_in"
get "sign_up" => "accounts#new", :as =>
"sign_up"
root :to => "pages#home"
resources :accounts
match ":controller(/:action(/:id(.:format)))"
end
[javascripts_controller.rb]
class JavascriptsController < ApplicationController
def getlocation
@states = State.find(:all)
@citys = City.find(:all)
end
end
//Niklas
On 22 Feb, 20:25, Hassan Schroeder
<hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> On Tue, Feb 22, 2011 at 10:51 AM, Niklas Nson
<niklasn...-5ZBJkHaGu7EwFerOooGFRg@public.gmane.org> wrote:
> > Yes i also belive that it dosent fire up. If i go to :
> >http://localhost:3000/javascripts/location_handler.js
>
> Oops. That''s the problem -- files under public are static, that
is, *not*
> interpreted. You need to put your file somewhere within app/views.
>
> --
> Hassan Schroeder ------------------------
hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
> twitter: @hassan
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
On Tue, Feb 22, 2011 at 8:33 PM, Niklas Nson <niklasnson-5ZBJkHaGu7EwFerOooGFRg@public.gmane.org> wrote:> I moved the file to /views/javascripts/getlocation.js.erb > But there must be something wrong with routes or something else > still. > > If i go to: http://localhost:3000/javascripts/getlocation.js i get a > No route matches "/javascripts/getlocation.js" error.Yes, that''s exactly the problem :-)> [Routes] > ModcubeApp::Application.routes.draw do > > get "log_in" => "sessions#new", :as => "log_in" > get "sign_up" => "accounts#new", :as => "sign_up" > root :to => "pages#home" > > resources :accounts > > match ":controller(/:action(/:id(.:format)))" > > endSo add that route and you''re done. -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
Does not match ":controller(/:action(/:id(.:format))) do the routing ? I thought it should look in controller and if not found look in public/ javascript ? //Niklas On 23 Feb, 14:05, Hassan Schroeder <hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Tue, Feb 22, 2011 at 8:33 PM, Niklas Nson <niklasn...-5ZBJkHaGu7EwFerOooGFRg@public.gmane.org> wrote: > > I moved the file to /views/javascripts/getlocation.js.erb > > But there must be something wrong with routes or something else > > still. > > > If i go to:http://localhost:3000/javascripts/getlocation.jsi get a > > No route matches "/javascripts/getlocation.js" error. > > Yes, that''s exactly the problem :-) > > > [Routes] > > ModcubeApp::Application.routes.draw do > > > get "log_in" => "sessions#new", :as => "log_in" > > get "sign_up" => "accounts#new", :as => "sign_up" > > root :to => "pages#home" > > > resources :accounts > > > match ":controller(/:action(/:id(.:format)))" > > > end > > So add that route and you''re done. > > -- > Hassan Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > twitter: @hassan-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
On Wed, Feb 23, 2011 at 5:17 AM, Niklas Nson <niklasnson-5ZBJkHaGu7EwFerOooGFRg@public.gmane.org> wrote:> Does not match ":controller(/:action(/:id(.:format))) do the routing ?Only if that pattern matches your request - which it doesn''t.>> > No route matches "/javascripts/getlocation.js" error.I see a controller, an action, and a format in that request - no id ... -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hassan, you are my hero.... Thank you for taking time ... Got it working :) /Niklas On 23 Feb, 14:25, Hassan Schroeder <hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Wed, Feb 23, 2011 at 5:17 AM, Niklas Nson <niklasn...-5ZBJkHaGu7EwFerOooGFRg@public.gmane.org> wrote: > > Does not match ":controller(/:action(/:id(.:format))) do the routing ? > > Only if that pattern matches your request - which it doesn''t. > > >> > No route matches "/javascripts/getlocation.js" error. > > I see a controller, an action, and a format in that request - no id ... > > -- > Hassan Schroeder ------------------------ hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > twitter: @hassan-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.