mravo
1
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!
mravo
2
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.
mravo
3
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
mravo
4
By the way, I’m pretty sure rails wants you to name your actions
some_action, not someAction.
On Jan 22, 5:12 pm, “[email protected]”
mravo
5
[email protected] 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, “[email protected]”
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!
mravo
6
[email protected] 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
I 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