Hi,
I''m currently using the latest version of rails 2.0.2 with cookies.
My problem is as follows, to which I''ve not found any help on google
etc.
I have a page which presents the user with two drop-down menus. The
first one, for example, asks for a car manufacurer, and the second,
which by default is blank, will ask for the model. Within my view I
use the following
<%= collection_select(:manufacturer, :manufacturer_id,
@manufacturers, :id, :description, options ={:prompt => "-Select a
Manufacturer"},
{
:onChange => "new
Ajax.Updater(''manufacturer_model_id'', ''/
models/list_by_manufacturer_id/''+ this[this.selectedIndex].value,
{asynchronous:true, evalScripts:true})"
}
) %>
<%= collection_select(:manufacturer, :model_id,
@models, :id, :description, options ={:prompt => "-Select a
model"})%>
The above works fine. When I choose a manufacturer from the first
selection it fires the js but rails then returns an error:
ActionController::InvalidAuthenticityToken
in ModelController#list_by_manufacturer_id
I believe the problem might be because I need to pass the
authenticity_token as part of the request, though I''m not sure, and if
so I''m uncertain as to how I go about passing it within the ajax call.
Any help/direction would be greatly appreciated
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
hiddenhippo
2008-Jan-02 10:59 UTC
Re: collection_select ajax.Updater InvalidAuthenticityToken
seems i might be getting a little closer with the following code
<%= collection_select(:manufacturer, :manufacturer_id,
@manufacturers, :id, :description, options ={:prompt => "-Select a
Manufacturer"},
{
:onChange =>
link_to_remote("",:update=>"manufacturer_model_id'',:url=>{:controller=>:models,
:action=>:list_by_manufacturer_id})
}
) %>
This seems to create the HTML etc correctly with the
authenticity_token, but when I click on the select list nothing is
every fired - no ajax call is ever made.
Any ideas?
On Jan 2, 10:11 am, hiddenhippo
<reda...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hi,
>
> I''m currently using the latest version of rails 2.0.2 with
cookies.
> My problem is as follows, to which I''ve not found any help on
google
> etc.
>
> I have a page which presents the user with two drop-down menus. The
> first one, for example, asks for a car manufacurer, and the second,
> which by default is blank, will ask for the model. Within my view I
> use the following
>
> <%= collection_select(:manufacturer, :manufacturer_id,
> @manufacturers, :id, :description, options ={:prompt => "-Select a
> Manufacturer"},
> {
> :onChange => "new
Ajax.Updater(''manufacturer_model_id'', ''/
> models/list_by_manufacturer_id/''+ this[this.selectedIndex].value,
> {asynchronous:true, evalScripts:true})"
> }
> ) %>
>
> <%= collection_select(:manufacturer, :model_id,
> @models, :id, :description, options ={:prompt => "-Select a
model"})%>
>
> The above works fine. When I choose a manufacturer from the first
> selection it fires the js but rails then returns an error:
>
> ActionController::InvalidAuthenticityToken
> in ModelController#list_by_manufacturer_id
>
> I believe the problem might be because I need to pass the
> authenticity_token as part of the request, though I''m not sure,
and if
> so I''m uncertain as to how I go about passing it within the ajax
call.
>
> Any help/direction would be greatly appreciated
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
hiddenhippo
2008-Jan-02 11:22 UTC
Re: collection_select ajax.Updater InvalidAuthenticityToken
dispite hoping to use link_to_remote I''ve ended up manually typing the
following;
<%= collection_select(:manufacturer, :manufacturer_id,
@manufacturers, :id, :description, options ={:prompt => "-Select a
Manufacturer"},
{
:onChange =>
"new Ajax.Updater
(''member_id_selection'',
''/models/list_by_manufacturer_id/''+
this[this.selectedIndex].value,
{asynchronous:true, evalScripts:true,
parameters:''authenticity_token=''+
encodeURIComponent(''"+form_authenticity_token.to_s+"'')}
)"
) %>
This actually works but seems but surely the helper method should have
worked. Does anyone knoe whether I could redo this in a far cleaner
way, i.e. using a helper?
thanks
On Jan 2, 10:59 am, hiddenhippo
<reda...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> seems i might be getting a little closer with the following code
>
> <%= collection_select(:manufacturer, :manufacturer_id,
> @manufacturers, :id, :description, options ={:prompt => "-Select a
> Manufacturer"},
> {
> :onChange =>
>
link_to_remote("",:update=>"manufacturer_model_id'',:url=>{:controller=>:models,
:action=>:list_by_manufacturer_id})
> }
>
> ) %>
>
> This seems to create the HTML etc correctly with the
> authenticity_token, but when I click on the select list nothing is
> every fired - no ajax call is ever made.
>
> Any ideas?
>
> On Jan 2, 10:11 am, hiddenhippo
<reda...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > Hi,
>
> > I''m currently using the latest version of rails 2.0.2 with
cookies.
> > My problem is as follows, to which I''ve not found any help on
google
> > etc.
>
> > I have a page which presents the user with two drop-down menus. The
> > first one, for example, asks for a car manufacurer, and the second,
> > which by default is blank, will ask for the model. Within my view I
> > use the following
>
> > <%= collection_select(:manufacturer, :manufacturer_id,
> > @manufacturers, :id, :description, options ={:prompt =>
"-Select a
> > Manufacturer"},
> > {
> > :onChange => "new
Ajax.Updater(''manufacturer_model_id'', ''/
> > models/list_by_manufacturer_id/''+
this[this.selectedIndex].value,
> > {asynchronous:true, evalScripts:true})"
> > }
> > ) %>
>
> > <%= collection_select(:manufacturer, :model_id,
> > @models, :id, :description, options ={:prompt => "-Select a
model"})%>
>
> > The above works fine. When I choose a manufacturer from the first
> > selection it fires the js but rails then returns an error:
>
> > ActionController::InvalidAuthenticityToken
> > in ModelController#list_by_manufacturer_id
>
> > I believe the problem might be because I need to pass the
> > authenticity_token as part of the request, though I''m not
sure, and if
> > so I''m uncertain as to how I go about passing it within the
ajax call.
>
> > Any help/direction would be greatly appreciated
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jan-02 11:25 UTC
Re: collection_select ajax.Updater InvalidAuthenticityToken
On 2 Jan 2008, at 10:59, hiddenhippo wrote:> > seems i might be getting a little closer with the following code > > > <%= collection_select(:manufacturer, :manufacturer_id, > @manufacturers, :id, :description, options ={:prompt => "-Select a > Manufacturer"}, > { > :onChange => > link_to_remote > ("",:update > > > > "manufacturer_model_id > '',:url=>{:controller=>:models, :action=>:list_by_manufacturer_id}) > } > > > ) %> > > > This seems to create the HTML etc correctly with the > authenticity_token, but when I click on the select list nothing is > every fired - no ajax call is ever made. >link_to_remote actually creates an <a> with an onclick that does the ajaxy stuff. In this sort of situation you want to use remote_function (takes basically the same arguments as link_to_remote, barring of course the first one) Fred> Any ideas? > > On Jan 2, 10:11 am, hiddenhippo <reda...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Hi, >> >> I''m currently using the latest version of rails 2.0.2 with cookies. >> My problem is as follows, to which I''ve not found any help on google >> etc. >> >> I have a page which presents the user with two drop-down menus. The >> first one, for example, asks for a car manufacurer, and the second, >> which by default is blank, will ask for the model. Within my view I >> use the following >> >> <%= collection_select(:manufacturer, :manufacturer_id, >> @manufacturers, :id, :description, options ={:prompt => "-Select a >> Manufacturer"}, >> { >> :onChange => "new Ajax.Updater(''manufacturer_model_id'', >> ''/ >> models/list_by_manufacturer_id/''+ this[this.selectedIndex].value, >> {asynchronous:true, evalScripts:true})" >> } >> ) %> >> >> <%= collection_select(:manufacturer, :model_id, >> @models, :id, :description, options ={:prompt => "-Select a model"}) >> %> >> >> The above works fine. When I choose a manufacturer from the first >> selection it fires the js but rails then returns an error: >> >> ActionController::InvalidAuthenticityToken >> in ModelController#list_by_manufacturer_id >> >> I believe the problem might be because I need to pass the >> authenticity_token as part of the request, though I''m not sure, and >> if >> so I''m uncertain as to how I go about passing it within the ajax >> call. >> >> Any help/direction would be greatly appreciated > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
hiddenhippo
2008-Jan-02 13:09 UTC
Re: collection_select ajax.Updater InvalidAuthenticityToken
thanks, that actually worked. I knew i must have been missing something. thanks again On Jan 2, 11:25 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 2 Jan 2008, at 10:59, hiddenhippo wrote: > > > > > > > seems i might be getting a little closer with the following code > > > <%= collection_select(:manufacturer, :manufacturer_id, > > @manufacturers, :id, :description, options ={:prompt => "-Select a > > Manufacturer"}, > > { > > :onChange => > > link_to_remote > > ("",:update > > > > > "manufacturer_model_id > > '',:url=>{:controller=>:models, :action=>:list_by_manufacturer_id}) > > } > > > ) %> > > > This seems to create the HTML etc correctly with the > > authenticity_token, but when I click on the select list nothing is > > every fired - no ajax call is ever made. > > link_to_remote actually creates an <a> with an onclick that does the > ajaxy stuff. In this sort of situation you want to use remote_function > (takes basically the same arguments as link_to_remote, barring of > course the first one) > > Fred > > > Any ideas? > > > On Jan 2, 10:11 am, hiddenhippo <reda...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Hi, > > >> I''m currently using the latest version of rails 2.0.2 with cookies. > >> My problem is as follows, to which I''ve not found any help on google > >> etc. > > >> I have a page which presents the user with two drop-down menus. The > >> first one, for example, asks for a car manufacurer, and the second, > >> which by default is blank, will ask for the model. Within my view I > >> use the following > > >> <%= collection_select(:manufacturer, :manufacturer_id, > >> @manufacturers, :id, :description, options ={:prompt => "-Select a > >> Manufacturer"}, > >> { > >> :onChange => "new Ajax.Updater(''manufacturer_model_id'', > >> ''/ > >> models/list_by_manufacturer_id/''+ this[this.selectedIndex].value, > >> {asynchronous:true, evalScripts:true})" > >> } > >> ) %> > > >> <%= collection_select(:manufacturer, :model_id, > >> @models, :id, :description, options ={:prompt => "-Select a model"}) > >> %> > > >> The above works fine. When I choose a manufacturer from the first > >> selection it fires the js but rails then returns an error: > > >> ActionController::InvalidAuthenticityToken > >> in ModelController#list_by_manufacturer_id > > >> I believe the problem might be because I need to pass the > >> authenticity_token as part of the request, though I''m not sure, and > >> if > >> so I''m uncertain as to how I go about passing it within the ajax > >> call. > > >> Any help/direction would be greatly appreciated--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
William Notowidagdo
2008-May-13 09:43 UTC
Re: collection_select ajax.Updater InvalidAuthenticityToken
hiddenhippo wrote:> thanks, that actually worked. I knew i must have been missing > something. > > thanks again >can you show me your controller? i have the same problem too. thanks --william -- Posted via http://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The code in question would lie in the view rather than the
controller. Stealing blindly from what was posted above:
<%= collection_select(:manufacturer, :manufacturer_id,
@manufacturers, :id, :description,
{:prompt => "-Select a Manufacturer"},
{ :onChange =>
remote_function(:url=>..., :method=>...,
:with=>"manufacturer_id")}
) %>
On May 13, 5:43 am, William Notowidagdo <rails-mailing-l...@andreas-
s.net> wrote:> hiddenhippo wrote:
> > thanks, that actually worked. I knew i must have been missing
> > something.
>
> > thanks again
>
> can you show me your controller? i have the same problem too.
>
> thanks
>
> --william
>
> --
> 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
William Notowidagdo
2008-May-14 01:50 UTC
Re: collection_select ajax.Updater InvalidAuthenticityToken
thank you all. my problem is done -- Posted via http://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---