{"action":"created","issue":{"url":"https://api.github.com/repos/blakechambers/matterhorn/issues/20","labels_url":"https://api.github.com/repos/blakechambers/matterhorn/issues/20/labels{/name}","comments_url":"https://api.github.com/repos/blakechambers/matterhorn/issues/20/comments","events_url":"https://api.github.com/repos/blakechambers/matterhorn/issues/20/events","html_url":"https://github.com/blakechambers/matterhorn/issues/20","id":64755848,"number":20,"title":"Support singleton resources","user":{"login":"blakechambers","id":46827,"avatar_url":"https://avatars.githubusercontent.com/u/46827?v=3","gravatar_id":"","url":"https://api.github.com/users/blakechambers","html_url":"https://github.com/blakechambers","followers_url":"https://api.github.com/users/blakechambers/followers","following_url":"https://api.github.com/users/blakechambers/following{/other_user}","gists_url":"https://api.github.com/users/blakechambers/gists{/gist_id}","starred_url":"https://api.github.com/users/blakechambers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blakechambers/subscriptions","organizations_url":"https://api.github.com/users/blakechambers/orgs","repos_url":"https://api.github.com/users/blakechambers/repos","events_url":"https://api.github.com/users/blakechambers/events{/privacy}","received_events_url":"https://api.github.com/users/blakechambers/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/blakechambers/matterhorn/milestones/1","html_url":"https://github.com/blakechambers/matterhorn/milestones/0.1.0%20-%20Initial%20release","labels_url":"https://api.github.com/repos/blakechambers/matterhorn/milestones/1/labels","id":1027856,"number":1,"title":"0.1.0 - Initial release","description":"","creator":{"login":"blakechambers","id":46827,"avatar_url":"https://avatars.githubusercontent.com/u/46827?v=3","gravatar_id":"","url":"https://api.github.com/users/blakechambers","html_url":"https://github.com/blakechambers","followers_url":"https://api.github.com/users/blakechambers/followers","following_url":"https://api.github.com/users/blakechambers/following{/other_user}","gists_url":"https://api.github.com/users/blakechambers/gists{/gist_id}","starred_url":"https://api.github.com/users/blakechambers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blakechambers/subscriptions","organizations_url":"https://api.github.com/users/blakechambers/orgs","repos_url":"https://api.github.com/users/blakechambers/repos","events_url":"https://api.github.com/users/blakechambers/events{/privacy}","received_events_url":"https://api.github.com/users/blakechambers/received_events","type":"User","site_admin":false},"open_issues":4,"closed_issues":10,"state":"open","created_at":"2015-03-18T18:29:38Z","updated_at":"2015-04-02T18:31:41Z","due_on":null,"closed_at":null},"comments":2,"created_at":"2015-03-27T12:44:49Z","updated_at":"2015-04-06T16:52:20Z","closed_at":null,"body":"See: https://github.com/josevalim/inherited_resources#singletons\r\n\r\nCurrently the actions generated for controllers are limited to generating\r\n[\"resources-style\"][resources] routes.  Matterhorn should also support the\r\naddition of [resource][resource] routing and actions.\r\n\r\nWe should create a concern, `Matterhorn::Resource` and `resource!`, to handle \r\nthe action generation.  The resource method should set the `default singleton: true` configuration so the url_helpers generate the correct paths.\r\n\r\n[resource]: http://api.rubyonrails.org/v2.3.8/classes/ActionController/Resources.html#M000310\r\n[resources]: http://api.rubyonrails.org/v2.3.8/classes/ActionController/Resources.html#M000309\r\n"},"comment":{"url":"https://api.github.com/repos/blakechambers/matterhorn/issues/comments/90152454","html_url":"https://github.com/blakechambers/matterhorn/issues/20#issuecomment-90152454","issue_url":"https://api.github.com/repos/blakechambers/matterhorn/issues/20","id":90152454,"user":{"login":"blakechambers","id":46827,"avatar_url":"https://avatars.githubusercontent.com/u/46827?v=3","gravatar_id":"","url":"https://api.github.com/users/blakechambers","html_url":"https://github.com/blakechambers","followers_url":"https://api.github.com/users/blakechambers/followers","following_url":"https://api.github.com/users/blakechambers/following{/other_user}","gists_url":"https://api.github.com/users/blakechambers/gists{/gist_id}","starred_url":"https://api.github.com/users/blakechambers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blakechambers/subscriptions","organizations_url":"https://api.github.com/users/blakechambers/orgs","repos_url":"https://api.github.com/users/blakechambers/repos","events_url":"https://api.github.com/users/blakechambers/events{/privacy}","received_events_url":"https://api.github.com/users/blakechambers/received_events","type":"User","site_admin":false},"created_at":"2015-04-06T16:52:20Z","updated_at":"2015-04-06T16:52:20Z","body":"I think I discussed this some with @Nakort.  Here's what I'm thinking:\r\n\r\nGenerally speaking, keeping models decoupled from controllers views is a generally accepted part of MVC design.  There are some exceptions to that even in standard rails application design.  An example of that is having a model method `to_param` which influences the way that the models urls are constructed in controllers and views.\r\n\r\nGiven your example: \r\n\r\n```ruby\r\nRails.application.routes.draw do\r\n  resources :posts do\r\n    resource :topic\r\n  end\r\n\r\n  resource  :topic\r\nend\r\n```\r\n\r\nIn the case above, topics can be both represented nested under posts (e.g. `post_topic_url`) or as a top level url (e.g. `topic_url`).  During serialization the code isn't sure which url is correct.\r\n\r\nI think theres a good use case for creating an instance method on the topic that is called when building the urls out.  \r\n\r\nIf a model responds_to `matterhorn_url_options`, then it should call that method and use the returned array of items to construct a url.\r\n\r\nNow, returning to the above example.  Assuming the above paths:\r\n\r\n```ruby\r\n# app/models/topic.rb\r\nclass Topic\r\n  \r\n  def matterhorn_url_options\r\n    [post_id, self]\r\n  end\r\n  \r\nend\r\n```\r\n\r\nThis would create links and templates to the nested version.  However, if the method was undefined, it would default to `[topic]`, which would create a route to the `topic_url`."}}