class Object

Constants

Jbuilder

Public Instance Methods

_cache_key(key, options) click to toggle source
# File lib/jbuilder/jbuilder_template.rb, line 202
def _cache_key(key, options)
  name_options = options.slice(:skip_digest, :virtual_path)
  key = _fragment_name_with_digest(key, name_options)

  if @context.respond_to?(:combined_fragment_cache_key)
    key = @context.combined_fragment_cache_key(key)
  else
    key = url_for(key).split('://', 2).last if ::Hash === key
  end

  ::ActiveSupport::Cache.expand_cache_key(key, :jbuilder)
end
_fragment_name_with_digest(key, options) click to toggle source
# File lib/jbuilder/jbuilder_template.rb, line 215
def _fragment_name_with_digest(key, options)
  if @context.respond_to?(:cache_fragment_name)
    @context.cache_fragment_name(key, **options)
  else
    key
  end
end
_is_active_model?(object) click to toggle source
# File lib/jbuilder/jbuilder_template.rb, line 227
def _is_active_model?(object)
  object.class.respond_to?(:model_name) && object.respond_to?(:to_partial_path)
end
_partial_options?(options) click to toggle source
# File lib/jbuilder/jbuilder_template.rb, line 223
def _partial_options?(options)
  ::Hash === options && options.key?(:as) && options.key?(:partial)
end
_render_active_model_partial(object) click to toggle source
# File lib/jbuilder/jbuilder_template.rb, line 265
def _render_active_model_partial(object)
  @context.render object, json: self
end
_render_explicit_partial(name_or_options, locals = {}) click to toggle source
# File lib/jbuilder/jbuilder_template.rb, line 244
def _render_explicit_partial(name_or_options, locals = {})
  case name_or_options
  when ::Hash
    # partial! partial: 'name', foo: 'bar'
    options = name_or_options
  else
    # partial! 'name', locals: {foo: 'bar'}
    if locals.one? && (locals.keys.first == :locals)
      options = locals.merge(partial: name_or_options)
    else
      options = { partial: name_or_options, locals: locals }
    end
    # partial! 'name', foo: 'bar'
    as = locals.delete(:as)
    options[:as] = as if as.present?
    options[:collection] = locals[:collection] if locals.key?(:collection)
  end

  _render_partial_with_options options
end
_set_inline_partial(name, object, options) click to toggle source
# File lib/jbuilder/jbuilder_template.rb, line 231
def _set_inline_partial(name, object, options)
  value = if object.nil?
    []
  elsif _is_collection?(object)
    _scope{ _render_partial_with_options options.merge(collection: object) }
  else
    locals = ::Hash[options[:as], object]
    _scope{ _render_partial_with_options options.merge(locals: locals) }
  end

  set! name, value
end
destroy() click to toggle source
# File lib/generators/rails/templates/api_controller.rb, line 44
def destroy
  @<%= orm_instance.destroy %>
end

private
  # Use callbacks to share common setup or constraints between actions.
  def set_<%= singular_table_name %>
    @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
  end

  # Only allow a list of trusted parameters through.
  def <%= "#{singular_table_name}_params" %>
    <%- if attributes_names.empty? -%>
    params.fetch(<%= ":#{singular_table_name}" %>, {})
    <%- else -%>
    params.require(<%= ":#{singular_table_name}" %>).permit(<
update() click to toggle source
# File lib/generators/rails/templates/api_controller.rb, line 34
def update
  if @<%= orm_instance.update("#{singular_table_name}_params") %>
    render :show, status: :ok, location: <%= "@#{singular_table_name}" %>
  else
    render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity
  end
end

# DELETE <%= route_url %>/1
# DELETE <%= route_url %>/1.json
def destroy
  @<%= orm_instance.destroy %>
end

private
  # Use callbacks to share common setup or constraints between actions.
  def set_<%= singular_table_name %>
    @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
  end

  # Only allow a list of trusted parameters through.
  def <%= "#{singular_table_name}_params" %>
    <%- if attributes_names.empty? -%>
    params.fetch(<%= ":#{singular_table_name}" %>, {})
    <%- else -%>
    params.require(<%= ":#{singular_table_name}" %>).permit