{"action":"created","issue":{"url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1400","labels_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1400/labels{/name}","comments_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1400/comments","events_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1400/events","html_url":"https://github.com/rails-api/active_model_serializers/issues/1400","id":123981116,"number":1400,"title":"[RFC] Option to decide whether a \"link\" should be a string or object","user":{"login":"groyoh","id":7434196,"avatar_url":"https://avatars.githubusercontent.com/u/7434196?v=3","gravatar_id":"","url":"https://api.github.com/users/groyoh","html_url":"https://github.com/groyoh","followers_url":"https://api.github.com/users/groyoh/followers","following_url":"https://api.github.com/users/groyoh/following{/other_user}","gists_url":"https://api.github.com/users/groyoh/gists{/gist_id}","starred_url":"https://api.github.com/users/groyoh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/groyoh/subscriptions","organizations_url":"https://api.github.com/users/groyoh/orgs","repos_url":"https://api.github.com/users/groyoh/repos","events_url":"https://api.github.com/users/groyoh/events{/privacy}","received_events_url":"https://api.github.com/users/groyoh/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-12-27T14:20:33Z","updated_at":"2015-12-28T02:05:40Z","closed_at":null,"body":"JSONAPI spec speficy that a `link` can either a string or an object (http://jsonapi.org/format/#document-links). Currently when using `ActiveModel::Serializer::link` method, we cannot specify whether the link should be serialized as a string or an object.\r\nIf we don't use a block, then it is always serialized as a string:\r\n```ruby\r\nlink :self, \"//a-url\" # => { :self => \"//an-url\" }\r\n```\r\nand if we use the block version, then it is always serialized as an object:\r\n```ruby\r\nlink :self do\r\n  href \"//a-url\"\r\nend # => { :self => { :href => \"//an-url\" } }\r\n```\r\n\r\nI see some cases where we might want to use a block (to have a dynamic href) but still want it to be serialized as a string (since it is allowed by the spec) or not use a block and serialize it as an object.\r\n\r\nI think an option parameter to the `Serializer::link` method could fix this e.g.\r\n```ruby\r\nlink :self, \"//an-url\", as_string: false # => { :self => { :href => \"//an-url\" } }\r\nlink :self, as_string: true do\r\n  href \"//an-url\"\r\nend # => { :self => \"//an-url\" }\r\n```"},"comment":{"url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/comments/167458891","html_url":"https://github.com/rails-api/active_model_serializers/issues/1400#issuecomment-167458891","issue_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1400","id":167458891,"user":{"login":"beauby","id":2215778,"avatar_url":"https://avatars.githubusercontent.com/u/2215778?v=3","gravatar_id":"","url":"https://api.github.com/users/beauby","html_url":"https://github.com/beauby","followers_url":"https://api.github.com/users/beauby/followers","following_url":"https://api.github.com/users/beauby/following{/other_user}","gists_url":"https://api.github.com/users/beauby/gists{/gist_id}","starred_url":"https://api.github.com/users/beauby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beauby/subscriptions","organizations_url":"https://api.github.com/users/beauby/orgs","repos_url":"https://api.github.com/users/beauby/repos","events_url":"https://api.github.com/users/beauby/events{/privacy}","received_events_url":"https://api.github.com/users/beauby/received_events","type":"User","site_admin":false},"created_at":"2015-12-28T02:05:40Z","updated_at":"2015-12-28T02:05:40Z","body":"@groyoh Not really, as you could currently do `link :self, { href: '//an-url' }`."}}