This repository has been archived by the owner on Nov 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
add convinent to get and combine associations attributes.
License
shaoshing/acts_as_provider
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
ActsAsProvider ============== Example ======= class Author < ActiveRecord::Base has_one photo end class Book < ActiveRecord::Base belongs_to author acts_as_provider do add.self add.author add.author.photo end end book = Book.new book.provide ["title", "content"] #=> same as { "title" => book.title, "content" => book.content } book.provide ["title", "author_name"] #=> same as { "title" => book.title, "author_name" => book.author.name } book.provide ["author_photo_file_type"] #=> same as { "author_photo_file_type" => book.author.photo.file_type } You can apply this plugin like this: Request: get books/1?fields[]=title&fields[]=content Controller: result = Book.find(params[:id]).provide params[:fields] TODO ======= 1. improve security to prevent: user.provide(["destroy"]) #=> Dangerous!! will destroy the record 2. support inheritant 3. improve performance with :include
About
add convinent to get and combine associations attributes.
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published