Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: Passing multiple parameters to form_for url?

This works great:

- form_for @user, :url => { :action => :create, :type => @type } do |f| ...

Returns /users/(id)?type=type

But in another view I need to pass TWO parameters into the URL string, and this does not work:

- form_for @user, :url => { :action => :update, :type => @type, :this => @currently_editing } do |f| ...

Returns /users/(id)?this=currently_editing

I've also tried:

- form_for @user, :url => { :action => :update, :params = params.merge({:this => @currently_editing, :type = @type})} do |f| ...

... with no luck (error: only GET requests allowed).

What I want is for it to return this: /users/(id)?this=currently_editing&type=type

Thoughts?

like image 796
neezer Avatar asked Oct 12 '09 19:10

neezer


Video Answer


2 Answers

please try to this

you can pass more than one parameter in this way.

- form_for @user, :url => xxx_yyy_path(:param1 => value1, :params2 => value2, ......) do |f| ...
like image 126
uma Avatar answered Oct 25 '22 23:10

uma


I would use hidden fields, but this should work:

<% form_for @user, :url => user_path(@user.id, :type => @type, :this => @currently_editing), :method => :put do |f| -%>

:method => :put triggers the update action when using RESTful routes.

like image 35
Hans Petter Wilhelmsen Avatar answered Oct 26 '22 00:10

Hans Petter Wilhelmsen