cerebris / jsonapi-resources

A resource-focused Rails library for developing JSON:API compliant servers.
http://jsonapi-resources.com
MIT License
2.31k stars 526 forks source link

Disable links #594

Open greyblake opened 8 years ago

greyblake commented 8 years ago

Hi! Thanks for the nice gem again.

I've tried to figured it out myself, but failed. Is there a legal way to disable links to resources? E.g. configuration option?

Thanks!

jhaber1 commented 8 years ago

Doesn't look like it. Was looking for this config option as well. As per the 1.0 spec having a links object is optional so it would be nice to have that reflected here, maybe in the vein of https://github.com/cerebris/jsonapi-resources/blob/master/lib/jsonapi/configuration.rb#L42.

davidgoli commented 8 years ago

:+1: Turning off links selectively is a strong nice-to-have, as eg. Ember 2.0 issues warnings when included relationships also have links. It would be nice as a rule to have an option just to turn off links for included relationships (or even make that default).

jeffreybiles commented 8 years ago

Agree, this would be great.

Does anyone have the illegal way to disable links? I'm about to source dive for it.

rossholdway commented 7 years ago

Did anyone ever figure out how to do this? This would be a really useful config option.

peco8 commented 7 years ago

I'm also curious about this, because if it's nested links are always broken.

santostiago commented 7 years ago

Is this being taken care of? :)

alvincrespo commented 6 years ago

Any recommendations on how we can go about disabling links for relationships?

masciugo commented 6 years ago

maybe at the end of this paragraph. But I am experiencing problem on creation because of this lines of code. I am still on 0.9 because I'am using mongoid

nicolas-besnard commented 5 years ago

I've been using this in a Resource:

def custom_links(options)
  {self: nil}
end
Shigawire commented 5 years ago

@nicolas-besnard

I've been using this in a Resource:

def custom_links(options)
  {self: nil}
end

Does not work for me: undefined method `[]' for nil:NilClass`.

Are you using version 0.10?

hailerity commented 4 years ago

With v.0.10.2, use string key instead of symbol key:

def custom_links(options)
  {'self' => nil}
end

Or better way:

class UserResource < JSONAPI::Resource
  exclude_links [:self, :related]
end
tommy-russoniello commented 3 years ago

Related https://github.com/cerebris/jsonapi-resources/issues/444.