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
order_id
which have atrue
status? Your intent isn't clear from your question, it would really help to have a better idea of what you're aiming for. – Benoit Garret