开发者

How to redirect from one form to another and passing a value to the second form?

I have a "mini" form on the home page which allows the user to select a car color and press submit. After doing so, the user is taken to another form where the previously selected car color is used to pre-populate a field in this other form.

The mini form is this:

<%= form_tag('/cars/new', :method => :get) %>
  <%= select "new_car", "color_id", Colors.find(:all, :order => "description asc").
        collect {|s| [ s.description, s.id ] }, {:include_blank => 'Select color'} %>

  <input type="submit" value="Submit"/>

On pressing submit, this routes to the correct action (/cars/new) but the URL in the address bar is:

http://localhost:3000/cars/new?utf8=✓&new_car[color_id]=12

Where I expected it to be:

http://localhost:3000/cars/new?color_id=12

How to make get the URL to look like the one above?

Another question, how exactly is the fo开发者_运维问答rm_tag to be used? How do you put a closing </form> tag?


For the block form of form_tag, see:

http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-form_tag

For the query string issue, there's a similar question here:

removing "utf8=✓" from rails 3 form submissions

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜