views:

606

answers:

4

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?

+3  A: 

Why do you need to pass them into the URL string? Why not just add them as hidden fields in the form? In almost all cases you should pass the variables that way with POSTs.

ScottD
Touché; I see the error of my ways. Thank ye, kind sir!
neezer
No problem. Your welcome.
ScottD
A: 

I think you have to move the desired querystring attributes outside of the :url option like this:

form_for @user, :url => { :action => :update }, :type => @type, :this => @currently_editing do |f|
rswolff
Nope. Doesn't work like that.
Jim
Right... it doesn't work like that.
rswolff
A: 

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.

HP
A: 

See my answer at http://www.ruby-forum.com/topic/205524#894744

RalphSHnelvar