Guest User

Untitled

a guest
Aug 16th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. How to represent / persist information for a table which will contain a dynamic set of configurations
  2. create table app (id, name, desc)
  3. create table app_config (id, app_id, key, value)
  4.  
  5. def change
  6. create_table :app_configs do |t|
  7. t.text :config
  8. t.integer :app_id
  9. t.timestamps
  10. end
  11. end
  12.  
  13. class App < ActiveRecord::Base
  14. has_many :app_configs
  15. ...
  16. end
  17. class AppConfig < ActiveRecord::Base
  18. belongs_to :app
  19. ...
  20. end
  21.  
  22. $ rails new testproject
  23. $ rails generate scaffold App name:string description:string
  24. $ rails generate scaffold AppConfig key:string value:string app:references
  25. $ rake db:migrate
  26.  
  27. resources :apps do
  28. resources :app_configs
  29. end
Add Comment
Please, Sign In to add comment