Skip to content

Files

Latest commit

4d278a9 · Apr 5, 2017

History

History
61 lines (52 loc) · 1.11 KB

README.md

File metadata and controls

61 lines (52 loc) · 1.11 KB

rails-module-railsadmin

Rails module for rails-admin.

step by step:

  • Add new filed for admin user:
# gem 'devise'
rails generate devise:install
rails generate devise User

## Or you can add admin field to the migration
# t.boolean :admin
rails g migration AddAdminToUser
  • Add auth to posts_contrlller:
before_action :authenticate_user!
  • check in home_controller:
class HomeController < ApplicationController
  def index
    if current_user
      redirect_to posts_path
    end
  end
end
  • Add to layout navations:
  <% if current_user %>
  <%= link_to 'logout' destroy_user_session_path, method: :delete%>
  <% else %>
  <%= link_to 'login' new_user_session_path %>
  <% end %>
  • Install rails_admin
# gem 'rails_admin'
rails g rails_admin:install
  • set authorization:
  config.authorize_with do
    redirect_to main_app.root_path unless warden.user.admin == true
  end
  • result:
1290657123@qq.com/admin true  ===> Can edit post/user 
other@qq.com /admin false     ===> Can not ....

resources: