I wrote my own generator, from console its launched like this
rails generate ead_document TechnicalOpinion --document_type_id=1
It creates model and migration. I want to execute generator from my controller without using ruby system command. Is there any way to do that?
Solution appears to be pretty simple:
This code in controller
Rails::Generators.invoke("ead_document", [@document_type.table_name.classify, "--document_type_id=#{@document_type.id}"])
is the same as this in console
rails generate ead_document TechnicalOpinion --document_type_id=1
In case you want to use it outside a controller, you may also want to require it explicitely:
require 'rails/generators'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With