0

I got this from here, but I don't know where to put and how I will execute this.

I tried to create class and run this thru console (rails c) but it is not working.

def setup_actions_controllers_db

  write_permission("all", "manage", "Everything", "All operations", true)

  controllers = Dir.new("#{Rails.root}/app/controllers").entries
  controllers.each do |controller|
    if controller =~ /_controller/
      foo_bar = controller.camelize.gsub(".rb","").constantize.new
    end
  end
  # You can change ApplicationController for a super-class used by your restricted controllers
  ApplicationController.subclasses.each do |controller|
    if controller.respond_to?(:permission)  
      clazz, description = controller.permission
      write_permission(clazz, "manage", description, "All operations")
      controller.action_methods.each do |action|
        if action.to_s.index("_callback").nil?
          action_desc, cancan_action = eval_cancan_action(action)
          write_permission(clazz, cancan_action, description, action_desc)
        end
      end
    end
  end

end

and so on ...

Kindly help me on this. Thank you

do_Ob
  • 709
  • 1
  • 6
  • 24

1 Answers1

1

You have to create a rake task with that code and run that task afterwards in order to populate your newly created Permission table. To create a rake task you need to add the file <newtask>.rake in lib/tasks/<newtask>.rake.

Brozorec
  • 1,163
  • 9
  • 15
  • Do you know how to create a rake task and run it? – Brozorec Oct 21 '15 at 09:08
  • Yeah. I already tried that. I created `namespace :permissions do task :exec => :environment do setup_actions_controllers_db end end` and run like this `rake permissions:exec` – do_Ob Oct 21 '15 at 09:21
  • I suppose you have a `permissions` table as described in the article. When you run the task, what did you have as errors? – Brozorec Oct 21 '15 at 09:24
  • I manage to run this now. Thanks. But the code is not working. I will debug it instead. Thanks – do_Ob Oct 21 '15 at 09:26