githubの公開鍵を作成しgithubに登録
Generating a new SSH key and adding it to the ssh-agent - User Documentation
#Open Terminal. #Paste the text below, substituting in your GitHub email address. ssh-keygen -t rsa -b 4096 -C "your_email@example.com" #This creates a new ssh key, using the provided email as a label. #Generating public/private rsa key pair. #When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location. #ここでなんの公開鍵がわかるようにid_rsa(ファイルの置き場所)の部分を書き換える Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter] #At the prompt, type a secure passphrase. For more information, see "Working with SSH key passphrases". #Enter passphrase (empty for no passphrase): [Type a passphrase] #Enter same passphrase again: [Type passphrase again]
pbcopy < ~/.ssh/ファイルの置き場所pub
githubがどのsshを使用するか設定する .sshの中にconfigというファイルを作成し下記の内容を記載する
Host github.com HostName github.com User git IdentityFile ~/.ssh/id_rsa_github
「Rails をはじめよう」をはじめる (1)
アプリケーションの作成
rails new blog
で新しいRails アプリケーションの作成 場所は自分が作成したいディレクトリ内で実行
すると
cd blog
そこに移動
rails server
rails serverを起動
http://localhost:3000/にアクセスすると
となる
Railsに"Hello"と挨拶させる
コントローラとビューが必要
コントローラは、アプリケーションに対する特定のリクエストを受け取って処理するのが役割です。 ルーティング は、リクエストをどのコントローラに割り振るかを決定するためのものです。 1つのコントローラに対して複数のルーティングがあるのはよくあることです。 そしてコントローラにはいくつかのアクション があります。 いくつかの異なるルーティングに対して、それぞれ異なるアクションを割り当てることができます。 それぞれのアクションは、情報を集めてビューに送り出すのが役割です。
ビューの役割は、この情報をユーザーが読める形式で表示することです。 ここで気を付けていただきたい重要な違いは、表示する情報を集めるのは コントローラであって、ビューではないということです。
ということ とりあえず、コントローラーからビューという流れはなんとなく理解 まずコントローラーが必要なので作成する
コントローラを新規作成
コントローラを新規作成するには、コントローラ用のジェネレータを実行します
# welcomeという名前のコントローラの中にindexというアクションを作成する
rails generate controller welcome index
Railsは指定どおりコントローラを作成し、関連ファイルやルーティングも設定してくれます
便利! 作られた場所もわかりやすく表示してくれます
create app/controllers/welcome_controller.rb route get 'welcome/index' invoke erb create app/views/welcome create app/views/welcome/index.html.erb invoke test_unit create test/controllers/welcome_controller_test.rb invoke helper create app/helpers/welcome_helper.rb invoke test_unit invoke assets invoke coffee create app/assets/javascripts/welcome.coffee invoke scss create app/assets/stylesheets/welcome.scss
welcomeコントローラ => app/controllers/welcome_controller.rb
indexビュー => app/views/welcome/index.html.erb に作成された
.erbがビューのようです
app/views/welcome/index.html.erbを開く
<h1>Welcome#index</h1> <p>Find me in app/views/welcome/index.html.erb</p>
こんな形になっているのをすべて書き換え保存
<h1>Hello, Rails!</h1>
これでコントローラーとビューが用意された
アプリケーションのホームページを設定する
サイトのルートURL http://localhost:3000 にアクセスしたときにこのメッセージが表示されるようにするには Railsで表示させたい実際のホームページの場所を指定する
エディタでconfig/routes.rbを開く
config/はアプリケーションの設定ファイル (ルーティング、データベースなど) がここに置かれます。
先ほどでてきた、ルーティングはここで設定するようです
config/routes.rb ルーティングファイルの内容
Rails.application.routes.draw do get 'welcome/index' # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end
外部からのリクエストをどのようにコントローラとアクションに振り分けるかを、DSL (ドメイン特化言語: domain-specific language) という特殊な言語を使用してこのファイル内に記述します。
Rails.application.routes.draw do get 'welcome/index' root 'welcome#index' # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end
root 'welcome/index' => アプリケーションのルートURLへのアクセスをwelcomeコントローラのindexアクションに割り当てるようRailsに指示が伝わる
get 'welcome/index' => http://localhost:3000/welcome/indexというリクエストをwelcomeコントローラのindexアクションに割り当てる
http://localhost:3000/welcome/indexを表示
まとめ: # アプリケーションの作成 rails new blog # そこに移動して cd blog # サーバーを起動し rails server # welcomeという名前のコントローラの中にindexというアクションを作成する rails generate controller welcome index # app/views/welcome/index.html.erb に表示させたい内容を記述 # config/routes.rb ルーティングファイルを設定
コマンドのヘルプを見る
rm のヘルプを見たい場合には
man rm
巨大ファイルを取り込むとき
set global max_allowed_packet = 16777216
mysqlの基礎
update
update people set birth_date = '1987-11-27' where id = 10096; # updateする テーブル名 set 変更内容 where 変更箇所 # peopleテーブルのidが10096のbirth_dateを'1987-11-27'にアップデートする
delete
delete from テーブル名 where 該当箇所;
insert
insert into people (id, birth_date, created_at, updated_at) values ('10097', '1987-03-03', NOW(), NOW()); # created_atとupdated_atがないと更新できない仕様に作られているテーブルにインサートする場合 NOW()は現在の時刻をタイムスタンプで記録してくれる
select inner_memoに'テスト'という文字列を含む行のidを取得
select id from people where memo like '%テスト%';
%テスト → で終わる
テスト_ → テストではじまりその後ろに任意の1文字がある
show databases;
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | 家計簿 | | blog_app | | mysql | | sys | | testdb | +--------------------+
desc テーブル名
カラム一覧を取得