instance method update

Ruby on Rails 2.13.0

Since v2.11.5 Last seen in v2.14.1

Available in: v2.11.5 v2.12.0 v2.13.0 v2.14.1

Signature

update()

No documentation comment.

Source
# File lib/generators/rails/templates/controller.rb, line 43
  def update
    respond_to do |format|
      if @<%= orm_instance.update("#{singular_table_name}_params") %>
        format.html { redirect_to <%= redirect_resource_name %>, notice: <%= %("#{human_name} was successfully updated.") %> }
        format.json { render :show, status: :ok, location: <%= "@#{singular_table_name}" %> }
      else
        format.html { render :edit, status: :unprocessable_entity }
        format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
      end
    end
  end

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

    respond_to do |format|
      format.html { redirect_to <%= index_helper %>_path, status: :see_other, notice: <%= %("#{human_name} was successfully destroyed.") %> }
      format.json { head :no_content }
    end
  end

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

    # Only allow a list of trusted parameters through.
    def <%= "#{singular_table_name}_params" %>
      <%- if attributes_names.empty? -%>
      params.fetch(<%= ":#{singular_table_name}" %>, {})
      <%- elsif Rails::VERSION::MAJOR >= 8 -%>
      params.expect(<%= singular_table_name %>: [ <%= permitted_params %> ])
      <%- else -%>
      params.require(<%= ":#{singular_table_name}" %>).permit

Defined in lib/generators/rails/templates/controller.rb line 43 · View on GitHub · Improve this page · Find usages on GitHub

Defined in Object

Type at least 2 characters to search.

↑↓ navigate · open · esc close