Sha256: ebb47022c29c1c9ebf00afbc6ee6dbe3e88d85e133e7e0e49254c0785baaa246

Contents?: true

Size: 1.68 KB

Versions: 31

Compression:

Stored size: 1.68 KB

Contents

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

  before_action :set_<%= singular_name.underscore %>, only: [:show, :edit, :update, :destroy]

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

  def show
  end

  def new
    @<%= singular_name.underscore %> = <%= class_name %>.new
  end

  def create
    @<%= singular_name.underscore %> = <%= class_name %>.new
    <% attributes.each do |attribute| -%>
@<%= singular_name.underscore %>.<%= attribute.name %> = params[:<%= singular_name.underscore %>][:<%= attribute.name %>]
    <% end %>
<% if named_routes? -%>
    if @<%= singular_name.underscore %>.save
      redirect_to <%= plural_name %>_url
    else
      render 'new'
    end
<% else -%>
    if @<%= singular_name.underscore %>.save
      redirect_to "/<%= plural_name %>"
    else
      render 'new'
    end
<% end -%>
  end

  def edit
  end

  def update
    <% attributes.each do |attribute| -%>
@<%= singular_name.underscore %>.<%= attribute.name %> = params[:<%= singular_name.underscore %>][:<%= attribute.name %>]
    <% end %>
<% if named_routes? -%>
    if @<%= singular_name.underscore %>.save
      redirect_to <%= plural_name %>_url
    else
      render 'new'
    end
<% else -%>
    if @<%= singular_name.underscore %>.save
      redirect_to "/<%= plural_name %>"
    else
      render 'new'
    end
<% end -%>
  end

  def destroy
    @<%= singular_name.underscore %>.destroy
<% if named_routes? -%>
    redirect_to <%= plural_name %>_url
<% else -%>
    redirect_to "/<%= plural_name %>"
<% end -%>
  end

private

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

Version data entries

31 entries across 31 versions & 2 rubygems

Version Path
ez-1.3.0 lib/generators/ez/resource/templates/dried/controller.rb
ez-1.2.0 lib/generators/ez/resource/templates/dried/controller.rb
ez-1.1.3 lib/generators/ez/resource/templates/dried/controller.rb
ez-1.1.2 lib/generators/ez/resource/templates/dried/controller.rb
ez-1.1.1 lib/generators/ez/resource/templates/dried/controller.rb
ez-1.1.0 lib/generators/ez/resource/templates/dried/controller.rb
ez-1.0.0 lib/generators/ez/resource/templates/dried/controller.rb
ez-0.9.9 lib/generators/ez/resource/templates/dried/controller.rb
ez-0.9.7 lib/generators/ez/resource/templates/dried/controller.rb
ez-0.9.6 lib/generators/ez/resource/templates/dried/controller.rb
ez-0.9.5 lib/generators/ez/resource/templates/dried/controller.rb
ez-0.9.1 lib/generators/ez/resource/templates/dried/controller.rb
ez-0.9.0 lib/generators/ez/resource/templates/dried/controller.rb
ez-0.8.7 lib/generators/ez/resource/templates/dried/controller.rb
ez-0.8.6 lib/generators/ez/resource/templates/dried/controller.rb
ez-0.7.0 lib/generators/ez/resource/templates/dried/controller.rb
ez-0.6.5 lib/generators/ez/resource/templates/dried/controller.rb
ez-0.6.4 lib/generators/ez/resource/templates/dried/controller.rb
ez-0.6.3 lib/generators/ez/resource/templates/dried/controller.rb
ez-0.6.2 lib/generators/ez/resource/templates/dried/controller.rb