Sha256: 5e7492442a69e1e35f253e0dce01959b0f9e861e6a67973f90ac6b343a3d0b83

Contents?: true

Size: 1.23 KB

Versions: 23

Compression:

Stored size: 1.23 KB

Contents

# rails generate effective:controller NAME [action action] [options]

# Generates a controller
# rails generate effective:controller Thing
# rails generate effective:controller Thing index edit create
# rails generate effective:controller Thing index edit create --attributes name:string description:text

module Effective
  module Generators
    class ControllerGenerator < Rails::Generators::NamedBase
      include Helpers

      source_root File.expand_path(('../' * 4) + 'lib/scaffolds', __FILE__)

      desc 'Creates a controller in your app/controllers folder.'

      argument :actions, type: :array, default: ['crud'], banner: 'action action'
      class_option :attributes, type: :array, default: [], desc: 'Included permitted params, otherwise read from model'

      def assign_actions
        @actions = invoked_actions
      end

      def assign_attributes
        @attributes = invoked_attributes.presence || resource.belong_tos_attributes.merge(resource_attributes)
        self.class.send(:attr_reader, :attributes)
      end

      def invoke_controller
        say_status :invoke, :controller, :white
      end

      def create_controller
        template 'controllers/controller.rb', resource.controller_file
      end

    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
effective_developer-0.5.5 lib/generators/effective/controller_generator.rb
effective_developer-0.5.4 lib/generators/effective/controller_generator.rb
effective_developer-0.5.3 lib/generators/effective/controller_generator.rb
effective_developer-0.5.2 lib/generators/effective/controller_generator.rb
effective_developer-0.5.1 lib/generators/effective/controller_generator.rb
effective_developer-0.5.0 lib/generators/effective/controller_generator.rb
effective_developer-0.4.16 lib/generators/effective/controller_generator.rb
effective_developer-0.4.15 lib/generators/effective/controller_generator.rb
effective_developer-0.4.14 lib/generators/effective/controller_generator.rb
effective_developer-0.4.13 lib/generators/effective/controller_generator.rb
effective_developer-0.4.12 lib/generators/effective/controller_generator.rb
effective_developer-0.4.11 lib/generators/effective/controller_generator.rb
effective_developer-0.4.10 lib/generators/effective/controller_generator.rb
effective_developer-0.4.9 lib/generators/effective/controller_generator.rb
effective_developer-0.4.8 lib/generators/effective/controller_generator.rb
effective_developer-0.4.7 lib/generators/effective/controller_generator.rb
effective_developer-0.4.6 lib/generators/effective/controller_generator.rb
effective_developer-0.4.5 lib/generators/effective/controller_generator.rb
effective_developer-0.4.4 lib/generators/effective/controller_generator.rb
effective_developer-0.4.3 lib/generators/effective/controller_generator.rb