This project is archived and is in readonly mode.
Rails 3 generators won't invoke custom generators
-
Piotr Sarnacki
Confirmed on both 3.0.3 and master. I can take a look at that.
-
Paul Odeon
Thanks and sorry about the dodgy formatting.
I'm still looking into it myself and I've got as far as the Rails::Generators.find_by_namespace class method which I'm guessing is the source of the problem.
P
-
Piotr Sarnacki
It seems that you need to have generator in form of MyHelper::ScaffoldGenerator or Rails::MyHelperGenerator, I think that's because there is no hook for :my_helper in scaffold generator.
-
Paul Odeon
I can confirm that setting up the generator in this way works.
Is this a feature or a bug?
I think the expectation would be that the default rails generated generators work out of the box with the rails generators.
This would mean that either the generated generators are created in the form MyHelper::ScaffoldGenerator, or that the search path for generators is expanded to include toplevel generators like MyHelperGenerator.
As to which is the right way to go, I'm not sure, although I'd lean towards expanding the search path.
-
Paul Odeon
I have created a patch which will expand the search path to include toplevel generators like MyHelperGenerator.
I'm not sure if it will break anything else though and I'm unsure how to proceed from here.
-
José Valim
- Importance changed from to Low
It is a feature. Rails needs to look for things inside namespaces, otherwise we would easily have conflicts. Maybe we should update the guide instead?
-
Paul Odeon
Perhaps, but it doesn't seem possible to plug in the generated generators without modifying their name and putting them into a new module.
This doesn't seem right.
I understand rails needs to namespace classes, but by default rails generators are put in the global namespace.
Unless this is changed it seems to me that the generator namespace search should be expanded to search the global namespace for its generators.
-
José Valim
Paul, it searched the global namespace but that was causing bugs, like loading improper generators, or even generators from other frameworks, like Merb. If you want to use a generator as a Rails hook, it needs to be inside the Rails namespace.
Note that all Rails generators are namespaced inside "Rails::". But they are allowed to be invoked as "rails:generator" as shortcut.
Generators that are not used as hooks, like devise, do not need to be namespaced.
-
Piotr Sarnacki
I think that best solution to that, would be to add proper namespacing to generators, so you can do:
rails g generator rails/my_helperCurrently it will generate lib/generators/my_helper instead of lib/generators/rails/my_helper.
Also, documentation change would be nice.
Paul: do you want to work on that or should I prepare the patch myself?
-
Paul Odeon
Yes, I'd agree with that.
As I've never submitted a patch myself before now I'd prefer to defer to you on this.
I could however do the documentation side of it?
-
Piotr Sarnacki
- Assigned user set to José Valim
I believe that it should work like that: https://github.com/rails/rails/pull/131
Paul: feel free to update guide, I'm not native speaker, so you'll probably do it better :)
-
Paul Odeon
Should I issue a pull request in the same way as you've done for the generator patch?
-
Piotr Sarnacki
Frankly, I don't know what is current best approach - I like pull requests as they are easier to review because of github's interface and you can easier commit additional changes.
-
Paul Odeon
Ok, I will give it a try and hopefully it gets accepted!
Cheers
Paul
-
José Valim
Documentation patches can be pushed straight to lifo/docrails project on github
-
Paul Odeon
Great, I'll start work on it now, but I'm assuming I don't want to push to docrails until the patch has been accepted?
-
José Valim
You can push documentation only patches straight to docrails. There is no need for the patch to be accepted. You may want to take a look at the documentation guidelines before doing so:
http://guides.rubyonrails.org/api_documentation_guidelines.html
-
Piotr Sarnacki
José Valim: I believe that Paul was talking about my patch: https://github.com/rails/rails/pull/131
I'm not sure if this is desired behavior but I would expect it to work like that.
-
Piotr Sarnacki
- Tag set to patch
-
Repository
- State changed from new to resolved
(from [7891de893951c780a1732747d430c33e998dd573]) Allow to generate namespaced generators [#6140 Rails 3 generators won't invoke custom generators state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
https://github.com/rails/rails/commit/7891de893951c780a1732747d430c... -
Repository
(from [e6928e8c35bfc22425916f334e9482f955bc8907]) Allow to generate namespaced generators [#6140 Rails 3 generators won't invoke custom generators state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
https://github.com/rails/rails/commit/e6928e8c35bfc22425916f334e948...
