Skip to content

Commit

Permalink
Use resource_route hook
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Apr 20, 2012
1 parent ff7191c commit cb30b62
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
@@ -0,0 +1,16 @@
require 'rails/generators/rails/resource_route/resource_route_generator'

module Rails
module Generators
class BareResourceRouteGenerator < ResourceRouteGenerator
def add_resource_route
return if options[:actions].present?
route_config = regular_class_path.collect{ |namespace| "namespace :#{namespace} do " }.join(" ")
route_config << "resources :#{file_name.pluralize}"
route_config << ", except: :edit"
route_config << " end" * regular_class_path.size
route route_config
end
end
end
end
29 changes: 17 additions & 12 deletions lib/rails-bare/application.rb
Expand Up @@ -46,20 +46,22 @@ def default_middleware_stack
end
end

def load_generators(app=self)
super
require 'rails/generators/rails/resource/resource_generator'
Rails::Generators::ResourceGenerator.class_eval do
def add_resource_route
return if options[:actions].present?
route_config = regular_class_path.collect{|namespace| "namespace :#{namespace} do " }.join(" ")
route_config << "resources :#{file_name.pluralize}"
route_config << ", except: :edit"
route_config << " end" * regular_class_path.size
route route_config
if Rails.version <= "3.2.3"
def load_generators(app=self)
super
require 'rails/generators/rails/resource/resource_generator'
Rails::Generators::ResourceGenerator.class_eval do
def add_resource_route
return if options[:actions].present?
route_config = regular_class_path.collect{|namespace| "namespace :#{namespace} do " }.join(" ")
route_config << "resources :#{file_name.pluralize}"
route_config << ", except: :edit"
route_config << " end" * regular_class_path.size
route route_config
end
end
self
end
self
end

private
Expand All @@ -68,6 +70,9 @@ def setup_generators!
generators = config.generators

generators.templates.unshift File::expand_path('../templates', __FILE__)
if Rails.version > "3.2.3"
generators.resource_route = :bare_resource_route
end

%w(assets css js session_migration).each do |namespace|
generators.hide_namespace namespace
Expand Down

0 comments on commit cb30b62

Please sign in to comment.