[openstreetmap/openstreetmap-website] Simplify user links (#1785)

Andy Allan notifications at github.com
Wed Mar 14 06:49:52 UTC 2018


Currently our views are full of very verbose links to users, for example:

> link_to contact.display_name, :controller => 'user', :action => 'view',  :display_name => contact.display_name

This can be simplified by using the "user_path" method, to something like

> link_to contact.display_name, user_path(contact.display_name)

Normally this could be made even easier, since rails does the right thing with `model_path(model)` by default. However, since we use the `display_name` in the url rather than the `id`, we first need to define `to_param` on the User model:

```
def to_param
  display_name
end
```
This then allows the links to be even more straightforward, namely:

> link_to contact.display_name, user_path(contact)

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/issues/1785
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20180314/a422c9c3/attachment.html>


More information about the rails-dev mailing list