Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Zesty Style Guide

* [Ruby](./ruby)
* [Rails](./rails)
32 changes: 32 additions & 0 deletions rails/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Rails Style

## Routing & Controllers

#### Avoid `member` and `collection` routes

```Ruby
# Bad

resources :catering_orders do
member do
post :cancel
end
end


# Good

resources :catering_orders do
resource :cancellation, only: [:create]
end

# -or-

resources :catering_orders
resources :catering_order_cancellation, only: [:create]
```

##### Why?
* Prevents existing controllers from becoming too busy
* Eases the use of ember-data
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this because ember-data makes assumptions about being RESTful?

In some cases it's useful to have a separate domain model for a catering-order-cancellation because:

  1. this guarantees that the catering-order doesn't need to be mutated accidentally,
  2. you can create a cancellation without necessarily loading the catering-order in the store.

There are good patterns for action style routes in Ember, notably with ember-api-actions.

* What were once simple concepts such as `cancel` or `accept` or `reject` usually grow to become substantial domain concepts of their own, meriting their own controller.