Per our conversation via comments. The problem looks like you need to seed
your database before you can use the rank
command.
So you can seed your dev database a few ways, via rails console
, using your app or modifying your seeds.rb
file.
I'm going to suggest you use your seeds.rb
file because it's idempotent ( http://en.wikipedia.org/wiki/Idempotence )
So open db/seeds.rb
or create one if you don't have one.
Create a few records:
Costproject.create(rank_order: 3, coststatus_id: 2, project_year: 2016)
Costproject.create(rank_order: 2, coststatus_id: 2, project_year: 2016)
Costproject.create(rank_order: 1, coststatus_id: 2, project_year: 2016)
This will insert 3 records into costprojects
table. You MUST have the coststatus_id and project_year set to those values per your scope. These won't work:
Costproject.create(rank_order: 10)
Costproject.create(rank_order: 20, coststatus_id: 10)
Costproject.create(rank_order: 30, coststatus_id: 2, project_year: 2013)
then via terminal you can run:
bundle exec rake db:seed
This rake task will run your seed file as if you were manually typing it in your rails console
.
Now you should be able to do Costproject.rank(:row_order).all
. The first model should have an id of 3
, assuming you ran your seed file on an empty database.
For more info:
What is the best way to seed a database in Rails?
http://railscasts.com/episodes/179-seed-data
http://www.jasonwieringa.com/rake_rails_and_databases/