9

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?

4 Answers 4

26

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.

Sign up to request clarification or add additional context in comments.

2 Comments

would hidden fields work for parameters that are not part of the post model?
You can still add the hidden fields to the form, you don't have to use the form_for helpers for it.
2

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.

Comments

2

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

Comments

-3

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|

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.