This file contains hidden or 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
update user SET password="$shiro1$SHA-512$1024$NE+wqQq/TmjZMvfI7ENh/g==$V4yPw8T64UQ6GfJfxYq2hLsVrBY8D1v+bktfOxGdt4b/9BthpWPNUy/CBk6V9iA0nHpzYzJFWO8v/tZFtES8CA==" UPSERT WHERE id="admin" |
This file contains hidden or 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
require 'rest-client' | |
require 'json' | |
url = 'http://api.icndb.com/jokes/random' | |
response = RestClient.get(url) | |
json = JSON.parse(response) | |
puts json.fetch("value").fetch("joke") |
This file contains hidden or 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 post_author(properties_or_obj = {}) | |
# Теперь пользователь может передать свой объект или просто хэш с параметрами | |
author = properties_or_obj.is_a?(Hash) ? properties_or_obj : properties_or_obj.to_author | |
# fetch позволяет передать блок, который вызывается если ключ не найден | |
name = author.fetch(:name) { raise KeyError, "Name must be supplied for Author API requests" } | |
email = author.fetch(:email) { raise KeyError, "Email must be supplied for Author API requests" } | |
api.send { | |
name: name, |
This file contains hidden or 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
https://zealdocs.org/ |
This file contains hidden or 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
2.7.2. Мелкое вложение | |
Один из способов избежать глубокого вложения (как показано выше) является создание экшнов коллекции в пространстве имен родителя, чтобы чувствовать иерархию, но не вкладывать экшны элементов. Другими словами, создавать маршруты с минимальным количеством информации для однозначной идентификации ресурса, например так: | |
resources :articles do | |
resources :comments, only: [:index, :new, :create] | |
end | |
resources :comments, only: [:show, :edit, :update, :destroy] | |
Эта идея балансирует на грани между наглядностью маршрутов и глубоким вложением. Существует сокращенный синтаксис для получения подобного с помощью опции :shallow: |
This file contains hidden or 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
+ gem 'capybara' | |
+ gem 'launchy' | |
First, install Capybara and Rspec for Rails. Capybara provides the following method: | |
save_and_open_page | |
When inserted into your code at the place where you would like to open your program, and when rspec is run, Capybara displays this message: | |
Page saved to /home/code/my_app_name/tmp/capybara/capybara-current-date-and-time.html with save_and_open_page. |
This file contains hidden or 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
gem 'annotate' | |
Add a comment summarizing the current schema to the top or bottom of each of your… | |
# == Schema Info | |
# | |
# Table name: line_items | |
# | |
# id :integer(11) not null, primary key | |
# quantity :integer(11) not null |
This file contains hidden or 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
postgres=# CREATE DATABASE test_database; | |
CREATE DATABASE | |
postgres=# CREATE USER test_user WITH password 'qwerty'; | |
CREATE ROLE | |
postgres=# GRANT ALL privileges ON DATABASE test_database TO test_user; | |
GRANT |