establish_connection
- ActiveRecord::ConnectionHandling
- self.establish_connection
- ここにDB名を書くと、そのテーブルだけそのDBを見に行く(らしい
class User < ApplicationRecord establish_connection :hogera end
const funcA = () => { | |
return Promise((resolve, reject) => { | |
resolve("funcA"); | |
}); | |
}; | |
const funcB = () => { | |
return Promise((resolve, reject) => { | |
resolve("funcB"); | |
}); |
establish_connection
class User < ApplicationRecord
establish_connection :hogera
end
[4] pry(main)> User.connected? | |
=> false | |
[5] pry(main)> User | |
=> User (call 'User.connection' to establish a connection) | |
[6] pry(main)> User.connection | |
(0.6ms) SET NAMES utf8mb4 COLLATE utf8mb4_bin, @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483 | |
=> #<ActiveRecord::ConnectionAdapters::Mysql2Adapter:0x00007fcf4c63beb0 | |
@config= | |
{:adapter=>"mysql2", | |
:encoding=>"utf8mb4", |
def reverse!(n) | |
(n.length / 2).times { |i| n[-(i + 1)], n[i] = n[i], n[-(i + 1)] } | |
n | |
end | |
def reverse(n) | |
n.length.downto(1).each_with_object([]) { |i, lst| lst << n[i - 1] } | |
end | |
p reverse! [1, 2, 3, 4] |
class ChangeColumnTypeOfTwitterId < ActiveRecord::Migration | |
def change | |
reversible do |r| | |
change_table :users do |t| | |
r.up { t.change :twitter_id, :integer, limit: 8 } | |
r.down { t.change :twitter_id, :string } | |
end | |
end | |
end | |
end |
production.log | |
production.log.1 | |
production.log.2 | |
production.log.3 |
require 'spec_helper' | |
feature 'Course' do | |
describe 'new course' do | |
scenario '新しいコースを作成する' do | |
visit new_course_path | |
fill_in 'course_title', with: 'なんかタイトル' | |
# NOTE 大事なのココな |
if @login_provider.destroy | |
redirect_to user_login_providers_path, notice: '削除しました' | |
else | |
redirect_to user_login_providers_path, notice: '削除できませんでした' | |
end |
> show processlist; | |
| 284788 | tbaba | localhost:33573 | forkwell_dev | Sleep | 1 | | NULL | | |
| 285029 | tbaba | localhost:37715 | forkwell_dev | Query | 3595 | Waiting for table metadata lock | SELECT DISTINCT `job_endorsements`.`id` AS t0_r0, `job_endorsements`.`job_id` AS t0_r1, `job_endors | | |
| 285342 | tbaba | localhost:43623 | forkwell_dev | Query | 3654 | Waiting for table metadata lock | ALTER TABLE `users` DROP `facebook_identifier` | | |
| 285347 | tbaba | localhost:43685 | forkwell_dev | Query | 3599 | Waiting for table metadata lock | SELECT `users`.* FROM `users` WHERE `users`.`id` IN (9987, 5353, 8381, 9298, 8885, 9979, 519, 5805, | | |
| 285350 | tbaba | localhost:43717 | forkwell_dev | Query | 3566 | Waiting for table metadata lock | SELECT `users`.* FROM `users` WHERE `users`.`id` = 298 LIMIT 1 |
irb(main):033:0> user = User.first | |
=> #<User id: 1, first_name: ‘Tatsuro’, last_name: ‘Baba’, email: ‘harakirisoul@gmail.com’> | |
irb(main):034:0> user.as_json | |
=> {"email"=>"user_1@example.com", "first_name"=>"User1", "id"=>1, "last_name"=>"USER1"} |