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 · May be fixed by #931
Open

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

james-em opened this issue May 17, 2022 · 0 comments · May be fixed by #931

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

Alexander-Senko added a commit to Alexander-Senko/draper that referenced this issue Aug 31, 2024
Decorator will respect `--model-name` passed to `scaffold_controller` or
`controller` generator.

That could be of a particular use to solve namespace issues
(e.g. when controllers are namespaced and models are not).

The specs have been refactored to reduce and DRY the code.

Resolves drapergem#919.
@Alexander-Senko Alexander-Senko linked a pull request Aug 31, 2024 that will close this issue
1 task
@Alexander-Senko Alexander-Senko linked a pull request Aug 31, 2024 that will close this issue
1 task
@Alexander-Senko Alexander-Senko self-assigned this Aug 31, 2024
Alexander-Senko added a commit to Alexander-Senko/draper that referenced this issue Sep 2, 2024
Decorator will respect `--model-name` passed to `scaffold_controller` or
`controller` generator.

That could be of a particular use to solve namespace issues
(e.g. when controllers are namespaced and models are not).

The specs have been refactored to reduce and DRY the code.

Resolves drapergem#919.
Alexander-Senko added a commit to Alexander-Senko/magic-presenter that referenced this issue Nov 18, 2024
Presenters should respect `--model-name` passed to `scaffold_controller`
generator or any other one supporting this option.

That could be of a particular use to solve namespace issues
(e.g., when controllers are namespaced and models are not).

See also drapergem/draper#919.
Alexander-Senko added a commit to Alexander-Senko/magic-presenter that referenced this issue Nov 19, 2024
Presenters should respect `--model-name` passed to `scaffold_controller`
generator or any other one supporting this option.

That could be of a particular use to solve namespace issues
(e.g., when controllers are namespaced and models are not).

See also drapergem/draper#919.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants