Include `href` or `to_param` when constructing URLs client side

One nice feature that Rails provides is easy changes to URL generation
(assuming the param starts with the ID). All you have to do is

```ruby
def to_param
  [id, name].to_param
end
```

and everything "Just Works". This is lost, however, if you're manually
constructing URLs on the client side. This is avoided, if as a general
rule of thumb, we let the server decide how to construct the URLs, and
pass that information along.
No, ActiveModel::Serializers implements it since we add it to Object.
On Sep 23, 2014 10:32 PM, "Sean Doyle" <notifications@github.com> wrote:

> In best-practices/README.md:
>
> > @@ -177,6 +177,23 @@ JavaScript
> >  ----------
> >
> >  * Use CoffeeScript.
> > +* Include a `to_param` or `href` attribute when serializing ActiveRecord models,
> > +  and use that when constructing URLs client side, rather than the ID. Example:
> > +
> > +  ```ruby
> > +  class PostSerializer < ActiveModel::Serializer
> > +    attributes :id, :content, :to_param
> > +
> > +    delegate :to_param, to: :object
>
> doesn't attributes :to_param end up being equivalent to delegate
> :to_param, to: :object?
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/thoughtbot/guides/pull/232/files#r17949033>.
>