module SmartManagement::ControllerScaffold
Private Class Methods
included(controller)
click to toggle source
# File lib/smart_management/controller_scaffold.rb, line 64 def self.included(controller) controller.decent_configuration do strategy DecentExposure::StrongParametersStrategy end name = controller.controller_name singular = name.singularize controller.expose(name, attributes: :resource_attributes) controller.expose(singular, attributes: :resource_attributes) controller.helper_method :resource controller.respond_to :html, :json end
Public Instance Methods
create()
click to toggle source
# File lib/smart_management/controller_scaffold.rb, line 16 def create resource.save if resource.valid? end
destroy()
click to toggle source
# File lib/smart_management/controller_scaffold.rb, line 24 def destroy resource.destroy respond_with(resource) end
index()
click to toggle source
# File lib/smart_management/controller_scaffold.rb, line 5 def index respond_to do |format| format.html { render 'index' } format.json { render json: json_values } end end
show()
click to toggle source
# File lib/smart_management/controller_scaffold.rb, line 12 def show respond_with(resource) end
update()
click to toggle source
# File lib/smart_management/controller_scaffold.rb, line 20 def update resource.save if resource.valid? end
Private Instance Methods
_prefixes()
click to toggle source
Calls superclass method
# File lib/smart_management/controller_scaffold.rb, line 77 def _prefixes super << 'smart_management' end
editable_columns_syms()
click to toggle source
# File lib/smart_management/controller_scaffold.rb, line 35 def editable_columns_syms editable_columns.map do |column| column.name.to_sym end end
index_builder()
click to toggle source
# File lib/smart_management/controller_scaffold.rb, line 85 def index_builder SmartManagement::IndexBuilder. new(scope, smart_management_options) end
json_values()
click to toggle source
# File lib/smart_management/controller_scaffold.rb, line 90 def json_values JsonConverter.new(index_builder, json_options).call end
pagination_options()
click to toggle source
# File lib/smart_management/controller_scaffold.rb, line 45 def pagination_options JSON.parse(params["pagination"]).symbolize_keys if params["pagination"] end
resource()
click to toggle source
# File lib/smart_management/controller_scaffold.rb, line 81 def resource @resource ||= send(singular_model_name) end
resource_attributes()
click to toggle source
# File lib/smart_management/controller_scaffold.rb, line 31 def resource_attributes params.require(singular_model_name.to_sym).permit(editable_columns_syms) end
search_options()
click to toggle source
# File lib/smart_management/controller_scaffold.rb, line 49 def search_options if params["search"] search_params = JSON.parse(params["search"]) if search_params["predicateObject"] search_params["predicateObject"].symbolize_keys end end end
smart_management_options()
click to toggle source
# File lib/smart_management/controller_scaffold.rb, line 58 def smart_management_options { sort: sort_options, pagination: pagination_options, search: search_options } end
sort_options()
click to toggle source
# File lib/smart_management/controller_scaffold.rb, line 41 def sort_options JSON.parse(params["sort"]).symbolize_keys if params["sort"] end