Module: Releaf::ActionController::Resources

Extended by:
ActiveSupport::Concern
Included in:
Releaf::ActionController
Defined in:
app/lib/releaf/action_controller/resources.rb

Instance Method Summary collapse

Instance Method Details

#load_resourceObject


39
40
41
42
43
44
45
# File 'app/lib/releaf/action_controller/resources.rb', line 39

def load_resource
  begin
    @resource = resource_class.find(params[:id])
  rescue ActiveRecord::RecordNotFound
    raise Releaf::RecordNotFound
  end
end

#new_resourceObject


35
36
37
# File 'app/lib/releaf/action_controller/resources.rb', line 35

def new_resource
  @resource = resource_class.new
end

#permitted_paramsObject

Returns which resource attributes can be updated with mass assignment.

The resulting array will be passed to strong_parameters “permit“


31
32
33
# File 'app/lib/releaf/action_controller/resources.rb', line 31

def permitted_params
  Releaf::ResourceParams.new(resource_class).values
end

#resource_classObject

Returns class.

Returns:

  • class


60
61
62
# File 'app/lib/releaf/action_controller/resources.rb', line 60

def resource_class
  @resource_class ||= self.class.resource_class
end

#resource_given?Boolean

Returns true if @resource is assigned (even if it's nil)

Returns:

  • (Boolean)

48
49
50
# File 'app/lib/releaf/action_controller/resources.rb', line 48

def resource_given?
  !!defined? @resource
end

#resource_paramsObject


19
20
21
# File 'app/lib/releaf/action_controller/resources.rb', line 19

def resource_params
  required_params.permit(*permitted_params)
end

#resourcesObject

Return ActiveRecord::Relation used in index

Returns:

  • ActiveRecord::Relation


55
56
57
# File 'app/lib/releaf/action_controller/resources.rb', line 55

def resources
  resource_class.all
end

#resources_per_pageObject

It sets various instance variables, that are later used in views and # controllers


24
25
26
# File 'app/lib/releaf/action_controller/resources.rb', line 24

def resources_per_page
  40
end