Forum: Ruby on Rails passing parameters to action

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
MaM o. (Guest)
on 2007-01-22 17:34
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!
MaM o. (Guest)
on 2007-01-22 18:10
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.
(Guest)
on 2007-01-22 18:12
(Received via mailing list)
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
(Guest)
on 2007-01-22 18:13
(Received via mailing list)
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"
MaM o. (Guest)
on 2007-01-22 22:45
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!
MaM o. (Guest)
on 2007-01-22 22:51
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
This topic is locked and can not be replied to.