-
Notifications
You must be signed in to change notification settings - Fork 524
Labels
Description
Hi,
I'm working on a project where Controllers and routes are namespaced but models are not.
This is how my scaffold are generated:
bundle exec rails g model Client first_name:string last_name:string
bundle exec rails g scaffold_controller Admin::Client first_name:string last_name:string --model-name=Client
When specifying --model-name=Client, it would be great if the decorator wasn't namespaced and also not in a namespace folder, just like the model.
An easy fix would be editing this file: https://github.com/drapergem/draper/blob/master/lib/generators/rails/decorator_generator.rb
and changing
def create_decorator_file
template 'decorator.rb', File.join('app/decorators', class_path, "#{file_name}_decorator.rb")
end
to
def create_decorator_file
if parent_options[:model_name].present?
template 'decorator.rb', File.join('app/decorators', "#{file_name}_decorator.rb")
else
template 'decorator.rb', File.join('app/decorators', class_path, "#{file_name}_decorator.rb")
end
end
and changing
https://github.com/drapergem/draper/blob/master/lib/generators/rails/templates/decorator.rb
<%- if parent_class_name.present? -%>
class <%= class_name %>Decorator < <%= parent_class_name %>
<%- else -%>
class <%= class_name %>
<%- end -%>
To not include ModuleName::ModelNameDecorator: class_name.split("::").last
Reactions are currently unavailable