Passing parameters to action


#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!


#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.


#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


#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, “removed_email_address@domain.invalid”


#5

removed_email_address@domain.invalid 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, “removed_email_address@domain.invalid”

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!


#6

removed_email_address@domain.invalid 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