class Para::ResourceGenerator
Public Instance Methods
Source
# File lib/generators/para/resource/resource_generator.rb, line 21 def add_resource_to_component_controller gsub_file "app/controllers/admin/#{ component_name.singularize }_component_controller.rb", /# You can access @component here/ do <<-RUBY @q = @component.#{ plural_file_name }.ransack(params[:q]) @resources = @q.result.page(params[:page]) RUBY end end
Source
# File lib/generators/para/resource/resource_generator.rb, line 17 def copy_resource_controller template 'resource_controller.rb', "app/controllers/admin/#{ plural_file_name }_controller.rb" end
Source
# File lib/generators/para/resource/resource_generator.rb, line 42 def generate_model generate 'model', file_name, attributes.map { |attr| "#{ attr.name }:#{ attr.type }" }.insert(-1, 'component:references').join(' ') end
Source
# File lib/generators/para/resource/resource_generator.rb, line 58 def insert_belongs_to_to_resource inject_into_file "app/models/#{ file_name }.rb", after: "belongs_to :component" do ", class_name: 'Para::Component::Base'" end end
Source
# File lib/generators/para/resource/resource_generator.rb, line 64 def insert_has_many_to_component inject_into_file "app/components/#{ component_name.underscore }_component.rb", after: "register :#{ component_name.underscore }, self" do "\n\n has_many :#{ plural_file_name }, class_name: '::#{ class_name }', inverse_of: :component, foreign_key: :component_id, dependent: :destroy" end end
Source
# File lib/generators/para/resource/resource_generator.rb, line 36 def insert_relation_to_show append_to_file "app/views/admin/#{ component_name.underscore }_component/show.html.haml" do "\n\n= listing_for(@resources)" end end
Source
# File lib/generators/para/resource/resource_generator.rb, line 30 def insert_route inject_into_file 'config/routes.rb', after: "component :#{ component_name.underscore } do" do "\n resources :#{ plural_file_name }" end end
Source
# File lib/generators/para/resource/resource_generator.rb, line 54 def migrate rake 'db:migrate' if options[:migrate] end
Source
# File lib/generators/para/resource/resource_generator.rb, line 50 def orderable generate 'para:orderable', file_name if options[:orderable] end
Source
# File lib/generators/para/resource/resource_generator.rb, line 13 def welcome say 'Creating resource...' end