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 IF NOT EXISTS countries ( | |
); |
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 dup_countries | |
AS SELECT * | |
FROM countries | |
WITH NO DATA; |
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 dup_countries | |
AS SELECT * | |
FROM countries; |
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 CreateSmartphones < ActiveRecord::Migration[6.1] | |
def change | |
create_table :smartphones do |t| | |
t.string :brand, null: false | |
t.string :model, null: false | |
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
<%= form_with model: @user, url: users_create_path do | field | %> | |
Name | |
<%= field.text_field :name %> | |
<br> | |
<%= field.submit :Create %> | |
<% 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 create | |
@user = User.new(users_params) | |
if @user.save | |
redirect_to @user | |
else | |
render "new" | |
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 UsersController < ApplicationController | |
def new | |
end | |
def create | |
end | |
def update | |
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 UsersController < ApplicationController | |
def new | |
end | |
def create | |
end | |
def update | |
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
create_table "passports", force: :cascade do |t| | |
t.integer "number" | |
t.integer "user_id", null: false | |
t.datetime "created_at", null: false | |
t.datetime "updated_at", null: false | |
t.index ["user_id"], name: "index_passports_on_user_id" | |
end | |
create_table "users", force: :cascade do |t| | |
t.string "name" |
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
validates_each :email do | record, attr, value | | |
# extracts email service | |
service = value.match(/\A\w+\.?\w*\@{1}([a-z]+)\.{1}[a-z]+\z/).to_a[1] | |
# creates error for the attribute | |
record.errors.add(attr, "#{service} email service is not allowed!") if service.in? %w(yahoo msn aol hotmail) | |
end |
NewerOlder