This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreateDefinitions < ActiveRecord::Migration[6.0] | |
def change | |
create_table :definitions do |t| | |
t.references :slang, index: true, foreign_key: true | |
t.string :language | |
t.string :meaning | |
t.timestamps | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Slang < ApplicationRecord | |
belongs_to :user | |
has_many :definitions, dependent: :destroy | |
has_many :slang_books | |
has_many :books, through: :slang_books | |
accepts_nested_attributes_for :definitions, :reject_if => proc {|attributes| | |
attributes.all? {|k,v| v.blank?}} | |
validates :phrase, presence: true | |
validates :origin, presence: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Definition < ApplicationRecord | |
belongs_to :slang | |
validates :meaning, presence: true | |
validates :language, presence: true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SlangsController < ApplicationController | |
before_action :require_login | |
skip_before_action :require_login, only: [:index, :search, :show] | |
def index | |
@slangs = Slang.all | |
end | |
def new | |
@slang = Slang.new | |
3.times{@slang.definitions.build} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Create New Slang</h1> | |
<%if flash[:errors]%> | |
<% flash[:errors].each do |error|%> | |
<%= error %> | |
<%end%> | |
<%end%> | |
<%= form_for @slang do |f|%> | |
<%=f.label :phrase%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create_table "definitions", force: :cascade do |t| | |
t.integer "slang_id" | |
t.string "language" | |
t.string "meaning" | |
t.datetime "created_at", precision: 6, null: false | |
t.datetime "updated_at", precision: 6, null: false | |
t.index ["slang_id"], name: "index_definitions_on_slang_id" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreateUsers < ActiveRecord::Migration[6.0] | |
def change | |
create_table :users do |t| | |
t.string :password_digest | |
t.string :username | |
t.string :address | |
t.boolean :board_certified | |
t.timestamps | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def change | |
create_table :appointments do |t| | |
t.timestamps | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ApplicationRecord | |
has_many :provider_appointments, foreign_key: :client_id, class_name: "Appointment" | |
has_many :providers, through: :provider_appointments | |
has_many :client_appointments, foreign_key: :provider_id, class_name: "Appointment" | |
has_many :clients, through: :client_appointments | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Appointment < ApplicationRecord | |
belongs_to :client, class_name: "User" | |
belongs_to :provider, class_name: "User" | |
end |
OlderNewer