Effective Questions
Underlying questions and responses module for use with polls, cpd audits and more.
An admin creates an acts_as_questionable resource with one or more questions.
The responses are collected by an acts_as_responsable resource with one or more responses
Works with action_text for content bodies, and active_storage for file uploads.
Getting Started
This requires Rails 6 and Twitter Bootstrap 4 and just works with Devise.
Please first install the effective_datatables gem.
Please download and install the Twitter Bootstrap4
Add to your Gemfile:
gem 'haml'
gem 'effective_questions'
Run the bundle command to install it:
bundle install
Then run the generator:
rails generate effective_questions:install
The generator will install an initializer which describes all configuration options and creates a database migration.
If you want to tweak the table names, manually adjust both the configuration file and the migration now.
Then migrate the database:
rake db:migrate
Set up your permissions:
# Regular signed up user. Guest users not supported.
if user.persisted?
end
if user.admin?
end
Usage
You can render the results with ``.
Authorization
All authorization checks are handled via the config.authorization_method found in the app/config/initializers/effective_questions.rb file.
It is intended for flow through to CanCan or Pundit, but neither of those gems are required.
This method is called by all controller actions with the appropriate action and resource
Action will be one of [:index, :show, :new, :create, :edit, :update, :destroy]
Resource will the appropriate object or class
The authorization method is defined in the initializer file:
# As a Proc (with CanCan)
config. = Proc.new { |controller, action, resource| (action, resource) }
# As a Custom Method
config. = :my_authorization_method
and then in your application_controller.rb:
def (action, resource)
current_user.is?(:admin) || EffectivePunditPolicy.new(current_user, resource).send('#{action}?')
end
or disabled entirely:
config. = false
If the method or proc returns false (user is not authorized) an Effective::AccessDenied exception will be raised
You can rescue from this exception by adding the following to your application_controller.rb:
rescue_from Effective::AccessDenied do |exception|
respond_to do |format|
format.html { render 'static_pages/access_denied', status: 403 }
format.any { render text: 'Access Denied', status: 403 }
end
end
License
MIT License. Copyright Code and Effect Inc.
Testing
Run tests by:
rails test
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Bonus points for test coverage
- Create new Pull Request