Class: Usman::UserRolesController
- Inherits:
-
ResourceController
- Object
- Kuppayam::BaseController
- ApplicationController
- ResourceController
- Usman::UserRolesController
- Defined in:
- app/controllers/usman/user_roles_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/usman/user_roles_controller.rb', line 29 def create @user = @r_object = User.find_by_id(permitted_params[:id]) if @user.add_role(@role) set_notification(true, I18n.t('status.success'), "Role '#{@role.name}' has been assigned to the user '#{@user.name}'") else set_notification(false, I18n.t('status.success'), "Failed to assign the Role '#{@role.name}'") end action_name = params[:action].to_s == "create" ? "new" : "edit" render_or_redirect(false, resource_url(@r_object), action_name) end |
#destroy ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/usman/user_roles_controller.rb', line 40 def destroy @user = @r_object = User.find_by_id(params[:id]) if @user if @user.remove_role(@role) get_collections (I18n.t('success.deleted'), :success) set_notification(true, I18n.t('status.success'), "Role '#{@role.name}' has been removed for the user '#{@user.name}'") @destroyed = true else = I18n.t('errors.failed_to_delete', item: default_item_name.titleize) (, :failure) set_notification(false, I18n.t('status.success'), "Failed to remove the Role '#{@role.name}'") @destroyed = false end else set_notification(false, I18n.t('status.error'), I18n.t('status.not_found', item: default_item_name.titleize)) end respond_to do |format| format.html {} format.js { js_view_path = @resource_options && @resource_options[:js_view_path] ? "#{@resource_options[:js_view_path]}/destroy" : :destroy render js_view_path } end end |
#index ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'app/controllers/usman/user_roles_controller.rb', line 7 def index get_collections respond_to do |format| format.html {} format.js { js_view_path = @resource_options && @resource_options[:js_view_path] ? "#{@resource_options[:js_view_path]}/index" : :index render js_view_path } end end |
#new ⇒ Object
24 25 26 27 |
# File 'app/controllers/usman/user_roles_controller.rb', line 24 def new @user = User.new render_accordingly end |
#show ⇒ Object
18 19 20 21 22 |
# File 'app/controllers/usman/user_roles_controller.rb', line 18 def show @user = @r_object = @resource_options[:class].find_by_id(params[:id]) set_notification(false, I18n.t('status.error'), I18n.t('status.not_found', item: default_item_name.titleize)) unless @r_object render_accordingly end |