Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scaffold generator: Invalid path when using --model-name=Record #919

Open
james-em opened this issue May 17, 2022 · 0 comments
Open

Scaffold generator: Invalid path when using --model-name=Record #919

james-em opened this issue May 17, 2022 · 0 comments

Comments

@james-em
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant