From a585cf824d46bf1ebc8f177b4b37adce0a6bf96f Mon Sep 17 00:00:00 2001 From: Gadikota Mohan Raja Date: Wed, 6 Jan 2016 14:54:22 +0530 Subject: [PATCH] Updated readme --- README.md | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2584d09..b466c71 100644 --- a/README.md +++ b/README.md @@ -20,14 +20,14 @@ require "sprockets/railtie" require "rails/test_unit/railtie" ``` -In config/environments/development.rb, remove or comment out +## In config/environments/development.rb, remove or comment out `config.active_record.migration_error = :page_load` you have to remove active_record helpers from the spec_helper -In application.rb +## In application.rb `config.app_middleware.delete "ActiveRecord::ConnectionAdapters::ConnectionManagement"` @@ -55,4 +55,59 @@ test: production: <<: *default +``` + +## For authentication +Used [Devise](https://github.com/neo4jrb/devise-neo4j) + +## For authorization +Used [Pundit](https://github.com/elabs/pundit) + +## Problem with namespaces in Pundit +Issue [Namespace Issue](https://github.com/elabs/pundit/issues/12) + +### My Solution + +policy/dashboard/home_policy.rb + +``` +module Dashboard + class HomePolicy < DashboardPolicy + def initialize(user, record) + @user = user + @record = record + end + + def show? + @user.present? + end + end +end + +``` + +policy/home_policy.rb + +``` +class HomePolicy < ApplicationPolicy + + def initialize(user, record) + @user = user + @record = record + end + + def show? + true + end +end + +``` + +dashboard/home_controller.rb +``` +def show + # send name of controller, which is the policy's qualifying name. + # and that's it voila. + authorize :"#{params[:controller]}", :show? +end ``` \ No newline at end of file