0

In my project, i have a situation like when user runs the application. The system should insert some values in a table which is used allover the application. (These value should be inserted only once when the project is executed at first time)

I am trying to find out if there is any initialization function like Constructors in Rails. I tried to use the config/application.rb, but i am not sure its the right way to do this.

Please suggest.

Thanks

2
  • 1
    use the migration and insert value into tables . Commented Apr 30, 2012 at 6:59
  • is it possible for me to insert values into table with migration script? Commented Apr 30, 2012 at 7:15

3 Answers 3

1

If you looking for inserting some default dictionary data like month names etc you should look into seed.rb file or even better consider using seed_fu gem (https://github.com/mbleigh/seed-fu)

Sign up to request clarification or add additional context in comments.

Comments

1

Yes you can insert/edit/delete records into table with migration :

1) Create the migration .

2) Run db query inside the execute. like :

execute "insert into users (name, role) values ('vik', 'admin')"

3) After all the insertion operation run the migration.

Comments

0

How if you update have boolean field or any kind of integer field to maintain status in your application. And for the very first time, user runs the application, your code will insert necessary values for that user in db and update boolean/status field and will be cached(for better performance only rather than fetching value from db every time). However after every time cache is cleared, it will send the query to db; but fetching boolean value(checking user status) is more faster than checking all inserted values for that user.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.