class Object

Public Instance Methods

<(%= " click to toggle source

Only allow a trusted parameter “white list” through.

# File lib/templates/rails/scaffold_controller/controller.rb, line 98
def <%= "#{singular_table_name}_params" %>
  if params.include?(:<%= singular_table_name %>)
    <%- if attributes_names.empty? -%>
    params[:<%= singular_table_name %>]
    <%- else -%>
    params.require(:<%= singular_table_name %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
    <%- end -%>
  else
    { }
  end
handle_update_failure(action) click to toggle source
# File lib/templates/rails/scaffold_controller/controller.rb, line 70
def handle_update_failure(action)
  if json_request?
    # add a model-level error and render the json response.
    @<%= singular_table_name %>.errors.add(:base, 'failed to save')
    render 'show', formats: [ :json ]
  else
    # render the appropriate action.
    render action
  end
end

def handle_update_success(*messages)
  if inline_request?
    # inline and json requests expect json on success.
    render 'show', formats: [ :json ]
  else
    # otherwise, we redirect.

    # The default behavior in rails is to redirect to the item that was updated.
    # The default behavior in incline is to redirect to the item collection.

    # To reinstate the default rails behavior, uncomment the line below.
    # redirect_to @<%= singular_table_name %>, *messages unless @<%= singular_table_name %>.destroyed?
    redirect_to <%= index_helper %>_url, *messages
  end
end
layout_to_use() click to toggle source

Inline requests do not get a layout, otherwise use the default layout.

# File lib/templates/rails/scaffold_controller/controller.rb, line 66
def layout_to_use
  inline_request? ? false : nil
end
locate() click to toggle source
# File lib/templates/rails/scaffold_controller/controller.rb, line 59
def locate
  render json: { record: @dt_request.record_location }
end