3

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

VPaskar
  • 667
  • 1
  • 6
  • 13

1 Answers1

7

You want runner.

#/bin/bash

# Maybe need to prefix with `bundle exec`
rails runner 'Station.create(…)'
Philip Hallstrom
  • 19,673
  • 2
  • 42
  • 46
  • 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 ` – VPaskar Feb 11 '16 at 21:57
  • That I can't help with other than to try it in the console and look for errors. – Philip Hallstrom Feb 11 '16 at 22:12