Created
February 25, 2016 01:50
-
-
Save Sudok/0ec683e7b41b3c26cbe3 to your computer and use it in GitHub Desktop.
controller de users no devise
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ControlUsersController < ApplicationController | |
before_action :authenticate_user! | |
before_action :set_user, only: [:show, :edit, :update, :destroy] | |
def index | |
@users = User.all | |
authorize @users | |
end | |
def show | |
end | |
def new | |
@user = User.new | |
authorize @user | |
end | |
def edit | |
end | |
def create | |
@user = User.new(user_params) | |
authorize @user | |
respond_to do |format| | |
if @user.save | |
format.html { redirect_to @user, notice: "Usuário salvo com sucesso!"} | |
else | |
format.html { render :new} | |
end | |
end | |
end | |
def update | |
respond_to do |format| | |
if @user.update(user_params) | |
format.html { redirect_to @user, notice: "Usuário atualizado com sucesso!"} | |
else | |
format.html { render :edit} | |
end | |
end | |
end | |
def destroy | |
@user.destroy | |
respond_to do |format| | |
format.html { redirect_to user_url, notice: "Usuário deletado com sucesso!"} | |
end | |
end | |
private | |
def set_user | |
@user = User.find(params[:id]) | |
authorize @user | |
end | |
def user_params | |
params.equire(:user).permit(:email, :role) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rails.application.routes.draw do | |
get 'control_users/index' | |
get 'control_users/index' | |
get 'control_users/new' | |
root 'welcome#index' | |
get 'welcome/index' | |
devise_for :users | |
resources :funs | |
#get 'series' => 'funs#index' | |
resources :movies | |
#get 'filmes' => 'movies#index' | |
resources :control_users | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserPolicy < ApplicationPolicy | |
def index? | |
user.admin? | |
end | |
def new | |
user.admin? | |
end | |
def create? | |
user.admin? | |
end | |
def update? | |
user.admin? | |
end | |
def destroy? | |
user.admin? | |
end | |
class Scope < Scope | |
def resolve | |
scope | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment