Class: ScaffoldPlus::Generators::CollectionGenerator

Inherits:
ActiveRecord::Generators::Base
  • Object
show all
Defined in:
lib/generators/scaffold_plus/collection/collection_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_routesObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/generators/scaffold_plus/collection/collection_generator.rb', line 13

def add_routes
  list = []
  routes.each do |route|
    view, verb = route.split(':')
    list << "      #{verb || 'get'} '#{view}'"
  end
  result = list.join("\n")
  gsub_file "config/routes.rb", /(^  resources :#{name.pluralize})$/,
            "\\1 do\n    collection do\n#{result}\n    end\n  end"
end

#add_viewsObject



24
25
26
27
28
29
# File 'lib/generators/scaffold_plus/collection/collection_generator.rb', line 24

def add_views
  routes.each do |route|
    @view = route.split(':').first
    template "view.html.erb", "app/views/#{table_name}/#{@view}.html.erb"
  end
end