Sha256: 8e3dfc089499af6e01a57a6d5a6f11d382fb9d5c87371d6a3441c0c5a15b0af4
Contents?: true
Size: 1.51 KB
Versions: 2
Compression:
Stored size: 1.51 KB
Contents
module MobileWorkflow module Generators # Custom scaffolding generator # https://github.com/rails/rails/blob/master/railties/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb class ControllerGenerator < Rails::Generators::NamedBase include Rails::Generators::ResourceHelpers source_root File.expand_path("../templates", __FILE__) class_option :attributes, type: :array, default: [], banner: "field:type field:type" class_option :actions, type: :array, default: [], banner: "index create update destroy" def copy_controller_and_spec_files template "controller.rb.erb", File.join("app/controllers", controller_class_path, "#{controller_file_name}_controller.rb") template "controller_spec.rb.erb", File.join("spec/controllers", controller_class_path, "#{controller_file_name}_controller_spec.rb") end private def attributes_names options[:attributes].map{ |attribute| attribute.split(":").first } end def permitted_params params = attributes_names.map{ |name| ":#{name}" } params.join(", ") end def rewrite_params if attributes_names init_params = "\n\t\tparams[:#{singular_table_name}] = {}\n" rewrite_params = attributes_names.map {|name| "params[:#{singular_table_name}][:#{name}] = params.dig(:payload, :#{name}, :answer)" }.join("\n\t\t") init_params + rewrite_params end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
mobile_workflow-0.3.1 | lib/generators/mobile_workflow/controller_generator.rb |
mobile_workflow-0.2.0 | lib/generators/mobile_workflow/controller_generator.rb |