This application is nothing more than a test of rolify, cancan and devise. The intent is to play around with the basic setup and test it’s functionality so that we know how much we can stretch the design for various implementations.
The basic install is from Eppo’s rolify tutorial: github.com/EppO/rolify/wiki/Tutorial
# rails generate devise:install
create config/initializers/devise.rb create config/locales/devise.en.yml
# Ensure you have defined default url options in your environments files. Here
is an example of default_url_options appropriate for a development environment in config/environments/development.rb: config.action_mailer.default_url_options = { :host => 'localhost:3000' } In production, :host should be set to the actual host of your application.
# Ensure you have defined root_url to something in your config/routes.rb.
For example: root :to => "home#index"
# flash messages in app/views/layouts/application.html.erb.
For example: <p class="notice"><%= notice %></p> <p class="alert"><%= alert %></p>
# rails generate devise User
invoke active_record create db/migrate/20140128165238_devise_create_users.rb create app/models/user.rb invoke test_unit create test/models/user_test.rb create test/fixtures/users.yml insert app/models/user.rb route devise_for :users
# rails generate cancan:ability
create app/models/ability.rb
# rails generate rolify:role
create app/models/role.rb insert app/models/user.rb create config/initializers/rolify.rb create db/migrate/20140128165256_rolify_create_roles.rb An initializer file has been created here: config/initializers/rolify.rb, you can change rolify settings to match your needs. Defaults values are commented out. A Role class has been been created in app/models (with the name you gave as argument otherwise the default is role.rb), you can add your own business logic inside. Inside your User class (or the name you gave as argument otherwise the default is user.rb), rolify method has been inserted to provide rolify methods. Now, if you just have to run the migration using rake command: rake db:migrate and you will be able to add the resourcify method inside all models you want scoped by a role.
# Copy Devise views into app - rails g devise:views
invoke Devise::Generators::SharedViewsGenerator create app/views/devise/shared create app/views/devise/shared/_links.erb invoke form_for create app/views/devise/confirmations create app/views/devise/confirmations/new.html.erb create app/views/devise/passwords create app/views/devise/passwords/edit.html.erb create app/views/devise/passwords/new.html.erb create app/views/devise/registrations create app/views/devise/registrations/edit.html.erb create app/views/devise/registrations/new.html.erb create app/views/devise/sessions create app/views/devise/sessions/new.html.erb create app/views/devise/unlocks create app/views/devise/unlocks/new.html.erb invoke erb create app/views/devise/mailer create app/views/devise/mailer/confirmation_instructions.html.erb create app/views/devise/mailer/reset_password_instructions.html.erb create app/views/devise/mailer/unlock_instructions.html.erb
# rake db:migrate
== DeviseCreateUsers: migrating ============================================== -- create_table(:users) -> 0.0033s -- add_index(:users, :email, {:unique=>true}) -> 0.0005s -- add_index(:users, :reset_password_token, {:unique=>true}) -> 0.0004s == DeviseCreateUsers: migrated (0.0044s) ===================================== == RolifyCreateRoles: migrating ============================================== -- create_table(:roles) -> 0.0007s -- create_table(:users_roles, {:id=>false}) -> 0.0003s -- add_index(:roles, :name) -> 0.0003s -- add_index(:roles, [:name, :resource_type, :resource_id]) -> 0.0004s -- add_index(:users_roles, [:user_id, :role_id]) -> 0.0004s == RolifyCreateRoles: migrated (0.0023s) =====================================