SHARE
TWEET

Untitled

a guest Mar 20th, 2017 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class CreateEquipment < ActiveRecord::Migration[5.0]
  2.   def change
  3.     create_table :equipment do |t|
  4.       t.string :sitename
  5.       t.string :equipname
  6.       t.string :equipmodel
  7.       t.string :equipmake
  8.       t.string :equiptype
  9.       t.belongs_to :site
  10.       t.timestamps
  11.     end
  12.   end
  13. end
  14.  
  15.  
  16. class CreateSites < ActiveRecord::Migration[5.0]
  17.   def change
  18.     create_table :sites do |t|
  19.       t.string :sitename
  20.  
  21.       t.timestamps
  22.     end
  23.   end
  24. end
  25.    
  26. class Equipment < ApplicationRecord
  27. end
  28.  
  29. class Site < ApplicationRecord
  30.  
  31.     has_many :equipment
  32.  
  33. end
  34.    
  35. enter code here
  36.    
  37. <div class="field">
  38.     <%= f.label :sitename %>
  39.     <%= f.collection_select :sitename, Site.all, :sitename, :sitename, prompt: true %>
  40.   </div>
  41.  
  42.   <div class="field">
  43.     <%= f.label :equipname %>
  44.     <%= f.text_field :equipname %>
  45.   </div>
  46.  
  47.   <div class="field">
  48.     <%= f.label :equipmodel %>
  49.     <%= f.text_field :equipmodel %>
  50.   </div>
  51.  
  52.  
  53. <div class="field">
  54.     <%= f.label :equipmake %>
  55.     <%= f.text_field :equipmake %>
  56.   </div>
  57.   <div class="field">
  58.     <%= f.label :equiptype %>
  59.     <%= f.text_field :equiptype %>
  60.   </div>
  61.  
  62.   <div class="actions">
  63.     <%= f.submit %>
  64.   </div>
  65. <% end %>
  66.    
  67. <p>
  68.   <strong>Sitename:</strong>
  69.   <%= @site.sitename %>
  70. </p>
  71.  
  72. <% @site.equipment.each do |equipment| %>
  73.   <p><%= equipment.equipname %></p>
  74. <% end %>
RAW Paste Data
Top