Skip to content
naaano edited this page Sep 21, 2012 · 18 revisions

ActiveScaffold by itself comes alone so you decide what to use or how to integrate into your solution, allowing to be flexible and avoid dependency problems. Following that approach, there are many gems you can install and ActiveScaffold will integrate them very well out of the box. Note that some of them need some config. So read on:

Data handling

User Interface

User & role management

As global user & management integration notes, you need to know that Active Scaffold uses “current_user” method to refer to interacting user in controllers, methods, helpers and views. Devise use the same convention, so you don’t have to do anything there. But in case you use another name, say account or just user, remember to alias it or define it in application_controller.rb:

def current_user 
  your_user_method
end
  • CanCan
    With CanCan you can control most of AS behavior and appearance per user and/or role. Add cancan as instructed, setup your favourite current_user strategy (devise, or whatever), and add this to map AS calls (row, show_search, etc.) to basic ones (create, read, update, delete). Note: you can omit this if you want fine control of each action.
    Ability#as_action_aliases should be called by the user in his ability class:
    class Ability < CanCan::Ability
      def initialize(current_user)
        as_action_aliases
      end
    end
    

    Set default permission rule for AS in ApplicationController:
    ActiveScaffold.set_defaults do |conf|
        conf.security.default_permission = false
      end
    

    Then, add rules based on role, user, or any other user related method:
    def initialize(current_user)
        as_action_aliases
        current_user ? user_rules(current_user) : guest_user_rules
        base_rules
      end
    def user_rules(user)
       user.roles.each do |role|
          exec_role_rules(role)
       end
       default_user_rules
    end
    def exec_role_rules( role)
        meth = :"#{role.name}_rules"
        send(meth) if respond_to? meth
      end
    def admin_rules
      can :manage, [Article, Post, User, Role]
    end
    

    Currently not supported: beggining_of_chain (skips cancan filtering), base AS security as fallback.

Clone this wiki locally