Sha256: fcf58386da8e118a93c80faac0acd5c9574ade25c4e681833e4d6fda9878c5e6
Contents?: true
Size: 1.06 KB
Versions: 49
Compression:
Stored size: 1.06 KB
Contents
require 'rails/generators/active_record' module ScaffoldPlus module Generators class CollectionGenerator < ActiveRecord::Generators::Base desc "Add a collection to a resource route" argument :name, type: :string, desc: "The object for the collection routes and views" argument :routes, type: :array, banner: "route[:verb=get] ...", desc: "The collection(s) to be added to NAME" source_root File.expand_path('../templates', __FILE__) 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 def add_views routes.each do |route| @view = route.split(':').first template "view.html.erb", "app/views/#{table_name}/#{@view}.html.erb" end end end end end
Version data entries
49 entries across 49 versions & 1 rubygems