Rails3 How can I use: params in a named scope?

I am trying to display a list of steps for a specific order. (Orders have many milestones.)

In my order model, I have the following:

scope :open, lambda { 
     joins("join milestones on milestones.order_id = orders.id").
      where("order_id = ? AND milestone_status = ?", :params[:order_id], true).
      group("orders.id")
    }

The problem I ran into is getting the current order id to work -: params [: order_id] is clearly wrong.

In my routes, I have the following:

resources :orders do
     resources :milestones
  end

And my url is as follows:

http://127.0.0.1/orders/2/milestones

How is this possible? I checked the scope, replacing it with the order ID manually.

- EDIT -

In accordance with the advice below, I put the following in my step controller:

@orders = Order.open( params[:order_id] )

And, in my opinion, I have this:

<% @ orders.each do | open | %>

But I get an error message:

wrong number of arguments (1 for 0)

Full stack: here http://pastie.org/2442518

+5
1

:

scope :open, lambda { |order_id|
 joins("join milestones on milestones.order_id = orders.id").
  where("order_id = ? AND milestone_status = ?", order_id, true).
  group("orders.id")
}

:

def index
    @orders = Order.open( params[:order_id] )
end
+4

All Articles