Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new feature #83

Closed
achempion opened this issue Aug 13, 2013 · 4 comments
Closed

new feature #83

achempion opened this issue Aug 13, 2013 · 4 comments

Comments

@achempion
Copy link

Lets add new config option that can delete any field from api response if field value is nil or false.
I suggest that it will be very useful.

@fabrik42
Copy link
Owner

@achempion
Copy link
Author

@fabrik42 need use it for each option but I write about all options at once.

I think that add something like allow_null: false to api_accessible options must be very userful

@fabrik42
Copy link
Owner

Hmm - I'm not sure about this. This basically makes your response schema unpredictable.

You can make it work yourself with something like this (not tested)

module ActsAsApi
  class ApiTemplate < Hash

    def add_if_present(val, options = {})
      options[:if] ||= lambda { |model| model.try(val).present? }
      add(val, options)
    end

  end
end

So you can use t.add_if_present in your Template definition instead of t.add.

@achempion
Copy link
Author

@fabrik42 great, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants