Class: FamilyGallery::ResourcesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/family_gallery/resources_controller.rb

Direct Known Subclasses

PicturesController, UserRolesController

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BaseFamilyGalleryController

#current_ability, #current_user

Class Method Details

.inherited(subclass) ⇒ Object

Set load_and_authorize for classes that extend this one.



3
4
5
6
7
8
9
10
11
# File 'app/controllers/family_gallery/resources_controller.rb', line 3

def self.inherited(subclass)
  name_match = subclass.name.match(/\AFamilyGallery::(.+)sController\Z/)
  class_name = "FamilyGallery::#{name_match[1]}"
  subclass.load_and_authorize_resource class_name: class_name

  subclass.__send__(:define_method, :resource_name) do
    name_match[1]
  end
end

Instance Method Details

#createObject



24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/family_gallery/resources_controller.rb', line 24

def create
  assign_params_to_resource_instance

  if resource_instance.save
    flash[:notice] = controller_t(".resource_was_saved")
    redirect_to resource_instance
  else
    render :new
  end
end

#destroyObject



53
54
55
56
57
58
59
60
61
# File 'app/controllers/family_gallery/resources_controller.rb', line 53

def destroy
  if resource_instance.destroy
    flash[:notice] = controller_t(".resource_was_deleted")
    redirect_to root_url
  else
    flash[:error] = resource_instance.errors.full_messages.join(". ")
    redirect_to resource_instance
  end
end

#editObject



38
39
40
# File 'app/controllers/family_gallery/resources_controller.rb', line 38

def edit
  assign_params_to_resource_instance
end

#indexObject



13
14
15
16
17
18
# File 'app/controllers/family_gallery/resources_controller.rb', line 13

def index
  @ransack = resource_class.ransack(params[:q])

  resources = @ransack.result.page(params[:page])
  instance_variable_set("@#{resource_plural_name}", resources)
end

#newObject



20
21
22
# File 'app/controllers/family_gallery/resources_controller.rb', line 20

def new
  assign_params_to_resource_instance
end

#showObject



35
36
# File 'app/controllers/family_gallery/resources_controller.rb', line 35

def show
end

#updateObject



42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/family_gallery/resources_controller.rb', line 42

def update
  assign_params_to_resource_instance

  if resource_instance.save
    flash[:notice] = controller_t(".resource_was_updated")
    redirect_to resource_instance
  else
    render :edit
  end
end