Sha256: 4157b716062da0b5985085dd3a2ac1ce6474868cf1b10df287f2a5e4afa4e01d

Contents?: true

Size: 1.08 KB

Versions: 14

Compression:

Stored size: 1.08 KB

Contents

<% module_namespacing do -%>
class <%= controller_class_name %>Controller < ApiController
  # include MobileWorkflow::S3Storable
  before_action :rewrite_payload, only: :create

  load_and_authorize_resource

  def index
    render json: @<%= plural_table_name %>.collect(&:list_item_as_json)
  end

  def show
    render json: @<%= singular_table_name %>.display_as_json
  end

  def create
    if @<%= singular_table_name %>.save
      render json: { binary_urls: binary_urls(@<%= singular_table_name %>), response: @<%= singular_table_name %> }, status: :created
    else
      head :unprocessable_entity 
    end
  end

  private
  def rewrite_payload
    # Use this method to make any changes to params to make them compatible with ActiveRecord
    
    # 1. Example to get selected id from a list
    # passport_id = params.dig(:payload, :choose_passport, :selected, :id)

    Rails.logger.debug "Pre-rewrite params: #{params}"
    # Do your rewriting here
  end

  def <%= singular_table_name.underscore %>_params
    params.require(:payload).permit(<%= permitted_params %>)
  end
end
<% end %>

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
mobile_workflow-0.6.0 lib/generators/mobile_workflow/templates/controller.rb.erb
mobile_workflow-0.5.11 lib/generators/mobile_workflow/templates/controller.rb.erb
mobile_workflow-0.5.10 lib/generators/mobile_workflow/templates/controller.rb.erb
mobile_workflow-0.5.9 lib/generators/mobile_workflow/templates/controller.rb.erb
mobile_workflow-0.5.8 lib/generators/mobile_workflow/templates/controller.rb.erb
mobile_workflow-0.5.7 lib/generators/mobile_workflow/templates/controller.rb.erb
mobile_workflow-0.5.6 lib/generators/mobile_workflow/templates/controller.rb.erb
mobile_workflow-0.5.5 lib/generators/mobile_workflow/templates/controller.rb.erb
mobile_workflow-0.5.4 lib/generators/mobile_workflow/templates/controller.rb.erb
mobile_workflow-0.5.3 lib/generators/mobile_workflow/templates/controller.rb.erb
mobile_workflow-0.5.2 lib/generators/mobile_workflow/templates/controller.rb.erb
mobile_workflow-0.5.1 lib/generators/mobile_workflow/templates/controller.rb.erb
mobile_workflow-0.5.0 lib/generators/mobile_workflow/templates/controller.rb.erb
mobile_workflow-0.4.0 lib/generators/mobile_workflow/templates/controller.rb.erb