简体   繁体   中英

How to run a rails script in production env

I have a script "tester.rb" in my local system and has below function

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

Start your rails console using rails c . 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.

If you don't want to use console and run it as a task then use Rake tasks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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