Add this line to your application's Gemfile:
gem 'frondit', github: 'jpmobiletanaka/frondit'And then execute:
$ bundle
Add to your ApplicationController
include Frondit
And then call from any controller you want:
frondit `policy`, [ only: `rules list, on: `actions list`, record: `record` ]
policy is a class_name or underscored class_name: Admin::PostPolicy or admin/post_policy
For example:
before_action :set_post
...
frondit :post_policy, only: %i[show? edit? update?], on: %i[index show], record: :@post
frondit AuthorPolicy, on: :index, record: :@post
frondit :book_policy, record: :@post
frondit Admin::PostPolicy
...
def set_post
@post = Post.find(params[:post_id])
end
record should be string/symbol with variable name which available before action.
You should declare before_action method with assigning variable before call frondit.
If your variable is @post, you should pass :@post or "@post" to frondit
After that your policies will be accessed from JS
policies() // => ArrayParticular policy:
policy('PostPolicy') // => Object
policy('PostPolicy').index // => true
policy('PostPolicy').edit // => falseBe careful, always use Pundit policies and his authorize method in your controllers while using Frondit.
Frondit isn't secure because of JS constrains.
Frondit supports Ruby 2.2+, Rails. 4.1+
- Tests coverage is poor