Skip to content

Instantly share code, notes, and snippets.

View ebrugulec's full-sized avatar
💃

Ebru Gulec ebrugulec

💃
  • Berlin, Germany
View GitHub Profile
Rails.application.routes.draw do
resources :todo_lists do
resources :todo_items do
member do
patch :complete
end
end
end
root 'todo_lists#index'
end
<p><%= todo_item.content %></p>
<%= link_to "Delete", todo_list_todo_item_path(@todo_list, todo_item.id), method: :delete, data: { confirm: "Are you sure?" } %>
<%= link_to "Mark as Complete", complete_todo_list_todo_item_path(@todo_list, todo_item.id), method: :patch %>
create_table "users", force: :cascade do |t|
t.string "email"
t.string "password_digest"
t.string "username"
t.string "token"
end
class AddEmailIndexToUsers < ActiveRecord::Migration
def change
add_index :users, :email
end
end
class CreateEmployees < ActiveRecord::Migration[5.1]
def change
create_table :employees do |t|
t.string :name
t.timestamps
end
end
end
class CreateProducts < ActiveRecord::Migration[5.1]
def change
create_table :products do |t|
t.string :title
t.timestamps
end
end
end
class CreatePictures < ActiveRecord::Migration[5.1]
def change
create_table :pictures do |t|
t.string :title
t.references :imageable, polymorphic: true, index: true
t.timestamps
end
end
end
class Employee < ApplicationRecord
has_many :pictures, as: :imageable
end
class Product < ApplicationRecord
has_many :pictures, as: :imageable
end
class Picture < ApplicationRecord
belongs_to :imageable, polymorphic: true
end