Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails Passing Parameter In URL

This is probably a very simple fix but I've been unable to find an answer just yet.

My application has orders and tasks. Orders have many tasks. When a user clicks new task in the show order view, it passes the order.id:

<%= link_to "New Task", new_task_path(:order_id=> @order.id) %>

The url shows:

/tasks/new?order_id=1

I just don't know how to extract this and use it in my form? I have tried:

<%= f.text_field :order_id, :value => @order_id %>

But it's not working.

like image 762
Jenny Blunt Avatar asked Jun 10 '11 12:06

Jenny Blunt


1 Answers

You can do:

<%= f.text_field :order_id, :value => params[:order_id] %>

Alternately, capture the value (with params) in the controller and assign it to @order_id there.

like image 90
Craig Stuntz Avatar answered Oct 13 '22 00:10

Craig Stuntz