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-1.3.0 lib/generators/ez/resource/templates/controller.rb
ez-1.2.0 lib/generators/ez/resource/templates/controller.rb
ez-1.1.3 lib/generators/ez/resource/templates/controller.rb
ez-1.1.2 lib/generators/ez/resource/templates/controller.rb
ez-1.1.1 lib/generators/ez/resource/templates/controller.rb
ez-1.1.0 lib/generators/ez/resource/templates/controller.rb
ez-1.0.0 lib/generators/ez/resource/templates/controller.rb
ez-0.9.9 lib/generators/ez/resource/templates/controller.rb
ez-0.9.7 lib/generators/ez/resource/templates/controller.rb
ez-0.9.6 lib/generators/ez/resource/templates/controller.rb
ez-0.9.5 lib/generators/ez/resource/templates/controller.rb
ez-0.9.1 lib/generators/ez/resource/templates/controller.rb
ez-0.9.0 lib/generators/ez/resource/templates/controller.rb
ez-0.8.7 lib/generators/ez/resource/templates/controller.rb
ez-0.8.6 lib/generators/ez/resource/templates/controller.rb
ez-0.7.0 lib/generators/ez/resource/templates/controller.rb
ez-0.6.5 lib/generators/ez/resource/templates/controller.rb
ez-0.6.4 lib/generators/ez/resource/templates/controller.rb
ez-0.6.3 lib/generators/ez/resource/templates/controller.rb
ez-0.6.2 lib/generators/ez/resource/templates/controller.rb