Sha256: 2c00cbd98b6d8d50ae81e6951bbb2977d646a47839955cd5139008add433bf84

Contents?: true

Size: 1.99 KB

Versions: 25

Compression:

Stored size: 1.99 KB

Contents

class <%= plural_name.camelize %>Controller < ApplicationController

  def index
    @<%= plural_name.underscore %> = <%= class_name %>.all
  end

  def show
    @<%= singular_name.underscore %> = <%= class_name %>.find_by(id: params[:id])
  end

  def new
  end

  def create
    @<%= singular_name.underscore %> = <%= class_name %>.new
<% attributes.each do |attribute| -%>
    @<%= singular_name.underscore %>.<%= attribute.name %> = params[:<%= attribute.name %>]
<% end -%>

<% if named_routes? -%>
    if @<%= singular_name.underscore %>.save
      redirect_to <%= plural_name %>_url, notice: "<%= singular_name.humanize %> created successfully."
    else
      render 'new'
    end
<% else -%>
    if @<%= singular_name.underscore %>.save
      redirect_to "/<%= plural_name %>", notice: "<%= singular_name.humanize %> created successfully."
    else
      render 'new'
    end
<% end -%>
  end

  def edit
    @<%= singular_name.underscore %> = <%= class_name %>.find_by(id: params[:id])
  end

  def update
    @<%= singular_name.underscore %> = <%= class_name %>.find_by(id: params[:id])
<% attributes.each do |attribute| -%>
    @<%= singular_name.underscore %>.<%= attribute.name %> = params[:<%= attribute.name %>]
<% end -%>

<% if named_routes? -%>
    if @<%= singular_name.underscore %>.save
      redirect_to <%= plural_name %>_url, notice: "<%= singular_name.humanize %> updated successfully."
    else
      render 'edit'
    end
<% else -%>
    if @<%= singular_name.underscore %>.save
      redirect_to "/<%= plural_name %>", notice: "<%= singular_name.humanize %> updated successfully."
    else
      render 'edit'
    end
<% end -%>
  end

  def destroy
    @<%= singular_name.underscore %> = <%= class_name %>.find_by(id: params[:id])
    @<%= singular_name.underscore %>.destroy

<% if named_routes? -%>
    redirect_to <%= plural_name %>_url, notice: "<%= singular_name.humanize %> deleted."
<% else -%>
    redirect_to "/<%= plural_name %>", notice: "<%= singular_name.humanize %> deleted."
<% end -%>
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
ez-0.6.1 lib/generators/ez/resource/templates/controller.rb
ez-0.6.0 lib/generators/ez/resource/templates/controller.rb
ez-0.5.0 lib/generators/ez/resource/templates/controller.rb
ez-0.0.3 lib/generators/ez/resource/templates/controller.rb
starter_generators-0.9.6 lib/generators/starter/resource/templates/controller.rb