13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/generators/happy_seed/roles/roles_generator.rb', line 13
def install_roles
return if already_installed
require_generator DeviseGenerator
gem 'cancancan'
Bundler.with_clean_env do
run "bundle install --without production"
run 'rake db:migrate'
end
template "ability.rb", "app/models/ability.rb"
directory "docs"
generate 'migration add_role_to_users role:integer'
inject_into_class "app/models/user.rb", "User", " enum role: [:user, :admin]\n"
inject_into_file 'app/controllers/application_controller.rb',
"\n\n def access_denied(exception)\n redirect_to root_path, alert: exception.message\n end\n",
before: /\nend/
end
|