I'm trying to display a list of milestones for a particular order. (Orders have many milestones.)
In my orders model, I have this:
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'm having is getting the current order ID to work - :params[:order_id] is clearly wrong.
In my routes I have this:
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 have tested the scope by replacing with an order ID manually.
-- EDIT --
As per advice below, I've put the following in my milestones controller:
@orders = Order.open( params[:order_id] )
And in my view, I have this:
<% @orders.each do |open| %>
But I get an error:
wrong number of arguments (1 for 0)
The full stacktrace is here: http://pastie.org/2442518
Define it like this:
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")
}
And call it on your controller like this:
def index
@orders = Order.open( params[:order_id] )
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With