How to invoke generators from code?

后端 未结 1 1328
南旧
南旧 2021-01-11 15:15

I wrote my own generator, from console its launched like this

rails generate ead_document TechnicalOpinion --document_type_id=1

It creates

相关标签:
1条回答
  • 2021-01-11 15:45

    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
    
    0 讨论(0)
提交回复
热议问题