orbit4-5/app/controllers/admin/roles_controller.rb

69 lines
1.4 KiB
Ruby
Raw Normal View History

2014-05-09 06:03:55 +00:00
class Admin::RolesController < OrbitMemberController
before_action :set_role, only: [:show, :edit , :update, :destroy]
def index
@roles = Role.all.asc("_id").entries
end
def show
end
def new
@role = Role.new
render layout: false
end
def edit
render layout: false
end
def create
@role = Role.new(role_params)
if @role.save
redirect_to admin_roles_url
else
@role = Role.new(role_params)
flash.now[:error] = t('create.error.category')
render action: :new
end
end
def update
if @role.update_attributes(role_params)
@role.role_fields.each{|t| t.destroy if t["to_delete"] == true}
redirect_to admin_roles_url
else
flash.now[:error] = t('update.error.category')
render action: :edit
end
end
def destroy
@role.destroy
respond_to do |format|
format.html { redirect_to admin_roles_url }
format.js { render 'admin/roles/destroy' }
end
end
def toggle
@role = Role.find(params[:role_id])
@role.disabled = @role.disabled ? false : true
@role.save!
redirect_to action: :index
end
private
# Use callbacks to share common setup or constraints between actions.
def set_role
@role = Role.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def role_params
params.require(:role).permit!
end
end