简体   繁体   English

如何在生产环境中运行 rails 脚本

[英]How to run a rails script in production env

I have a script "tester.rb" in my local system and has below function我的本地系统中有一个脚本“tester.rb”并且具有以下功能

def getAccountUpdate(Id)
   user = User.find_by_id(Id)
   user.name = "Default"
end 

How will i be able to run the function which is present in my local system .我将如何能够运行本地系统中存在的功能。 how will i run this function in the production rails console我将如何在生产 Rails 控制台中运行此功能

Start your rails console using rails c .使用rails c启动您的 rails 控制台。 Write like below.像下面这样写。

irb(main):001:0> def get_account_update(id)
irb(main):002:1> user = User.find_by_id(id)
irb(main):003:1> user.name = "Default"
irb(main):004:1> end
=> :get_account_update
irb(main):005:0> get_account_update(1)

If you want to run it in production use RAILS_ENV=production bundle exec rails c to start the console and write it.如果您想在生产中运行它,请使用RAILS_ENV=production bundle exec rails c启动控制台并编写它。

If you don't want to use console and run it as a task then use Rake tasks.如果您不想使用控制台并将其作为任务运行,请使用 Rake 任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM