I understand that,
But in my instance orders is not only a child of customers, it’s a
bonafide
resource of it’s own, accessible via:
/orders/
/orders/1/
/orders/1;edit
So, if we are viewing a customer/orders page, /customers/1/orders/ and
they click on “Edit Order”. Do we goto:
/customers/1/orders/1;edit #edit order #1
Or
/orders/1;edit #edit order #1
Do we implement both methods for the same function?
Syntactically, I think I like the both approach. If a user clicks on
“Edit
Order” from within a customer orders details view, its pretty apparent
where
they should return after completing the edit.
From: [email protected]
[mailto:[email protected]] On Behalf Of Ed Hickey
Sent: Wednesday, February 14, 2007 10:24 AM
To: [email protected]
Subject: [Rails] Re: RESTful design/url question
you can use the builtin helper:
edit_order_path(@customer,@order)
that will create a link like “/customers/1/order/1;edit”
new_order_path(@customer) will create a link to “/customer/1/order/new”
ed
On 2/14/07, Meech [email protected] wrote:
Thanks a bunch.
Follow-up question if you don’t mind…
You are on the page to view a customers orders:
/customers/1/orders/
User clicks edit, Would you replicate the edit, ala:
/customers/1/orders/1;edit
Or kick 'em to the orders resource?
/orders/1;edit
I’d like to be able to click “New Order” from within the customer
view,
something like
/customers/1/orders/new
But the replication doesn’t feel very DRY.
-----Original Message-----
From: [email protected]
[mailto:[email protected]
mailto:[email protected] ] On Behalf Of Jeff
Sent: Wednesday, February 14, 2007 9:43 AM
To: Ruby on Rails: Talk
Subject: [Rails] Re: RESTful design/url question
On Feb 14, 8:25 am, “Meech” < [email protected]
mailto:[email protected] > wrote:
New to rails and restful design, forgive me if this has been
asked…
Not at all.
Lets say you have customers and orders models. orders
belongs_to
customers.
When viewing a customer, (/customers/1/) I want to present the
option
to view the customers orders (and eventually invoices, POs, etc).
What route would be within restful guidelines?
/customers/1:orders
/customers/1?view=orders
/customers/1/orders/
/orders:filter?customer=1
I believe it would be /customers/1/orders/ . You achieve this by
specifying
that orders are nested within customers in your routes.rb:
map. resources :customers do |customer|
customer.resources :orders
end
and then, in your OrdersController class, use a before_filter to
identify
the customer, something like:
before_filter :get_customer
def get_customer
@customer = Customer.find(params[:customer_id])
end
The customer_id key is automatically created for you when you nest
the
routes.
I think I would prefer each “page” of a customer detail have it’s
own
controller method – this will allow me to keep the security
decisions
completely within the controller easily.
That’s how Rails works anyway - each “page” is an “action”. An
action is a
coupling of a controller method and a template (.rhtml page). So
you’re on
the right track.
Hope this helps
Jeff
softiesonrails.com