Sha256: cb13995ce5e1b1b50b169885ebfc1ef12ef37bfac70818ba856e01816e4ff4f1

Contents?: true

Size: 801 Bytes

Versions: 1

Compression:

Stored size: 801 Bytes

Contents

require 'rails/generators'

# Public: Generator for admin page controllers.
class AdminGenerator < Rails::Generators::NamedBase
  source_root File.expand_path('../templates', __FILE__)

  def create_admin_page_controller
    @controller = file_name
    template(
      'admin_page_controller.rb.erb',
      "app/controllers/admin/#{@controller.underscore}_controller.rb"
    )
  end

  def add_admin_route
    route "admin_for :#{@controller.underscore}"
  end

  def add_form_view
    unless Dir.exist?(Rails.root.join('app/views/admin'))
      Dir.mkdir(Rails.root.join('app/views/admin'))
    end

    create_file "app/views/admin/#{@controller.underscore}/_form.html.erb", <<VIEW
<% # "f" is exposed as a form object (example below) %>

<%= f.input :name %>
<%= f.button :submit %>
VIEW
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ceo-0.2.0 lib/generators/admin/admin_generator.rb