ruby - How to add a new column correctly within a rails application without relying on migrations? -


lets user bob wants keep track of meals calories every day, breakfast, lunch, dinner, , snack. make table within rails containing 4 columns (breakfast, lunch, dinner, snack), , bob puts in calories per meal every day no issues. few days later, bob decides wants include brunch, first thought write new migration add in brunch column, fine if small scale application , such changes happen rarely, do if app used multiple people, each person wanting add in own food time name?

surely migrations not way, require dev step in , modify rails application every time, many times per day. so, there way within rails application, limitation of activerecord, or not way should done?

for can add new table e.g. "lookup_food_types" having column id , food_type. assuming keeping calories in table named "calories". in calories table need have modification. columns "id, user_id, lookup_food_type_id".

so in lookupfoodtype model,

attr_accessible :food_ype has_many :calories 

and in calory model,

attr_accessible :user_id, :lookup_food_type_id belongs_to :lookup_food_type 

in lookup_food_types table need add record like

 id food_type -----------------  1  breakfast  2  lunch  3  dinner  4  snack 

now basic food type every users. if user wants add new food type beside basic food_types, can add new column in calories table named 'custom_food_type'

and in form user going add calory, need show calory input , food_type select box. , button, if user wants add own food type. , upon clicking button text field "custom_food_type" visible. condition that, user should not select type of food type basic list. can achieve using jquery.

hope solve problem.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -