Hi,
I have this action in my controller:
def someAction(someParam)
....
end
I want to call this action from JS
like so:
<%= remote_function (:url => {:action => "someAction",
:someParam => 3})
%>
but this doesn''t work. How can I pass an argument to a controller
(eficiently)?
Thanks for your help!
--
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 solution I found is this:
def someAction
...
@newParam = params[:someParam] #@newParam is now 3
...
end
<%= remote_function (:url => {:action => "someAction",
:someParam =>
"3"})%>
cheers
ps. if there is a better way, I''d like to know, please.
--
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
-~----------~----~----~----~------~----~------~--~---
augustlilleaas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jan-22 16:12 UTC
Re: passing parameters to action
Controller methods doesn''t work like that. Say you have this: link_to "Test", :action => "test_action", :id => 5, :some_param => "test" This would be the controller: def test_action params[:id] #returns 5 params[:some_param] #returns "test" end On Jan 22, 4:34 pm, MaM o_0 <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi, > I have this action in my controller: > > def someAction(someParam) > .... > end > > I want to call this action from JS > like so: > > <%= remote_function (:url => {:action => "someAction", :someParam => 3}) > %> > > but this doesn''t work. How can I pass an argument to a controller > (eficiently)? > Thanks for your help! > > -- > 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 -~----------~----~----~----~------~----~------~--~---
augustlilleaas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jan-22 16:12 UTC
Re: passing parameters to action
By the way, I''m pretty sure rails wants you to name your actions some_action, not someAction. On Jan 22, 5:12 pm, "augustlille...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <augustlille...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Controller methods doesn''t work like that. > > Say you have this: link_to "Test", :action => "test_action", :id => 5, > :some_param => "test" > > This would be the controller: > > def test_action > params[:id] #returns 5 > params[:some_param] #returns "test" > end > > On Jan 22, 4:34 pm, MaM o_0 <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > Hi, > > I have this action in my controller: > > > def someAction(someParam) > > .... > > end > > > I want to call this action from JS > > like so: > > > <%= remote_function (:url => {:action => "someAction", :someParam => 3}) > > %> > > > but this doesn''t work. How can I pass an argument to a controller > > (eficiently)? > > Thanks for your help! > > > -- > > 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 -~----------~----~----~----~------~----~------~--~---
augustlilleaas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> By the way, I''m pretty sure rails wants you to name your actions > some_action, not someAction. > > On Jan 22, 5:12 pm, "augustlille...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org"Thank you for showing me that. Yes, I''m naming my actions with ''_'' but I have so strange names I have to rename them for forum;). Thanks! -- 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 -~----------~----~----~----~------~----~------~--~---
augustlilleaas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> Controller methods doesn''t work like that. > > Say you have this: link_to "Test", :action => "test_action", :id => 5, > :some_param => "test" > > This would be the controller: > > def test_action > params[:id] #returns 5 > params[:some_param] #returns "test" > endI have found that I can pass arrays to action like: :action => "test_action", :id={1,2,3}. Is this ok, or is it "rail-abuse";)? thanks -- 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 -~----------~----~----~----~------~----~------~--~---