I need to wirte a bash script to run commands in my rails console, the commands are : Station.create(......)
#!/bin/bash
rails console
After this line i have no ideas. i tried echo "Station.create(...), but it doesn't help
asked Feb 11, 2016 at 19:54
VPaskar
6671 gold badge6 silver badges14 bronze badges
1 Answer 1
You want runner.
#/bin/bash
# Maybe need to prefix with `bundle exec`
rails runner 'Station.create(...)'
answered Feb 11, 2016 at 21:23
Philip Hallstrom
19.9k2 gold badges44 silver badges47 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
VPaskar
when i try to create a new station in rails console it does not create a new record.
#!/bin/bash rails runner 'Station.create(cd:"BK",station: "bla", icao: "BKBK", iata:"BKK", synop:"77777", lat:"55.55", lon:"555.55", elev: "5", mflag: "K", nexrad:"K", country_code:"BK", plotting:"5")' exit 0 Philip Hallstrom
That I can't help with other than to try it in the console and look for errors.
Explore related questions
See similar questions with these tags.
lang-bash