class Rails::Generators::ResourceRouteGenerator
:nodoc:
def add_resource_route
end
resources :products
namespace :users do
namespace :admin do
should give you
$ rails generate resource admin/users/products
Properly nests namespaces passed into a generator
:nodoc:
def add_resource_route return if options[:actions].present? # iterates over all namespaces and opens up blocks regular_class_path.each_with_index do |namespace, index| write("namespace :#{namespace} do", index + 1) end # inserts the primary resource write("resources :#{file_name.pluralize}", route_length + 1) # ends blocks regular_class_path.each_index do |index| write("end", route_length - index) end # route prepends two spaces onto the front of the string that is passed, this corrects that. # Also it adds a \n to the end of each line, as route already adds that # we need to correct that too. route route_string[2..-2] end
def route_length
def route_length regular_class_path.length end
def route_string
def route_string @route_string ||= "" end
def write(str, indent)
def write(str, indent) route_string << "#{" " * indent}#{str}\n" end