在rails控制台中运行ruby文件(Run ruby file in rails console)

我创建了一个文件ebm.rb脚本,用于在rails中向数据库添加新条目。

该文件很长,并使用一些rails模型。

我可以在rails console轻松执行ebm.rb吗?

我尝试了load和require东西,但这没有用。 我的ebm.rb文件位于C:\Sites\ebm ,我的rails项目位于C:\Sites\rublesql 。

I've created a file ebm.rb script to add new entries to a database in rails.

The file is very long, and uses some rails models.

Can I easily execute ebm.rb in the rails console?

I tried something with load and require, but that didn't work. My ebm.rb file is located in C:\Sites\ebm and my rails project in C:\Sites\rublesql.

最满意答案

您可以在rails应用程序的上下文中运行文件中的代码

rails runner

http://guides.rubyonrails.org/command_line.html#rails-runner

You can run the code in the file in the context of your rails app with

rails runner

http://guides.rubyonrails.org/command_line.html#rails-runner

更多推荐