RickBlog

恩返し

7/26〜8/13 メモ

7/26

ユーザーがURLにアクセス ⇒ ルーティングが仕分け ⇒ コントローラーが値を入れる ⇒ ビューがコントローラーから渡された値を表示

 

7/29

Controller 作成

 

・コントローラー名は複数形

 

rails g controller users index show

rails generate  controller コントローラー名(users) アクション名(index) アクション名(show) アクション名・・・

 

自動生成される

app/controllers/users_controller.rb

app/views/users/index.html.erb

app/views/users/show.html.erb

 

7/29

Link to

 

<li><%= link_to "Home",    root_path %></li>

<li><%= link_to "Help",    help_path %></li>

 

root_path -> '/'

root_url  -> 'http://www.example.com/'

 

help_path -> '/help'

help_url  -> 'http://www.example.com/help'

 

7/31

リアルタイム log

heroku logs --tail

heroku logs -t

 

rails console routes

 

7/31

controller & model削除

 

rails destroy controller コントローラー名

rails destroy controller users index show

 

 

rails destroy model モデル名 

rails destroy model task name:string description:text due_date:date done:bookean

 

8/1

heroku(ヘロク)とは、PaaSPlatform as a Serviceと呼ばれるサービスで、アプリケーションを実行するためのプラットフォームです。

もう少しわかりやすく説明すると、サーバやOS、データベースなどの「プラットフォーム」と呼ばれる部分を、インターネット越しに使えるようにしてくれるサービスの一つです。

レンタルサーバーと似ていると思うかもしれませんが、レンタルサーバーとPaaS「環境を貸してくれる」という意味では一緒なので、ほぼ同じと考えても問題はありません。

レンタルサーバサービスの進化版(プラットフォームレンタルサービス)のようなものと捉えるとひとまずはわかりやすいかもしれません。

 

8/1

データベースを作るコマンド

rake db:create

作成される db/development.sqlite3

 

モデル作成 例

rails g model user name:string username:string location:string about:text

→app/models/user.rb

→db/migrate/20130630062417_create_users.rb

 

モデルはusersではなく、userという単数形

コントローラー名は複数形

 

データベースに反映

rake db:migrate

 

 

seedというのは種

rake db:seed

 

<%………%>

このイコールのないものは、「HTMLとして表示する必要のないもの」

 

 

rake db:reset

  1. 全てのテーブルを drop
  2. "db/schema.rb" を元にテーブルを再作成

 

 

テーブル定義を変更した上で全てのレコードを空にしたいような場合

rake db:migrate:reset

  1. 全てのテーブルを drop
  2. "db/migrate/" 以下の全ての migration を実行してテーブルを再作成

 

heroku run rails db:migrate

 

8/1

Errno::ENOENTの対処

Spring kill 行う

ターミナル再起動

 

8/1 PostgreSQL関連

https://teratail.com/questions/47630

http://myutaro.blogspot.com/2017/03/cloud9-herokupostgresql.html

https://rails-study.net/cloud9-postgresql/

https://qiita.com/wb773/items/248e6e083b2fe12e820a

https://t4traw.github.io/2018030809-23.html

https://teratail.com/questions/121880

https://qiita.com/taKassi/items/8e43171aeda300b67213

https://qiita.com/NaokiIshimura/items/550ca82e8e57aaea5582

http://niki12260714.hatenablog.com/entry/2018/05/17/105557

 

時間をJST

https://qiita.com/sutoh/items/b7d23990abb9c5083daa

 

8/2

アセットパイプライン 方法2つ

https://qiita.com/hogehoge1234/items/9a94ebc93c5f937502cd

 

https://www.transnet.ne.jp/2016/02/28/rails%E5%88%9D%E5%AD%A6%E8%80%85%E3%81%8C%E3%81%A4%E3%81%BE%E3%81%9A%E3%81%8Dcolnr%E3%80%8C%E3%82%A2%E3%82%BB%E3%83%83%E3%83%88%E3%83%91%E3%82%A4%E3%83%97%E3%83%A9%E3%82%A4%E3%83%B3/

 

サーバの選び方

https://qiita.com/you8/items/670bfa6573cec2494c96

 

8/3

https://qiita.com/sunaga70/items/1f0add0dbcd0564cafee

 

8/7

https://us-east-2.console.aws.amazon.com/cloud9/ide/0b7020c9bb7d4628a00e75f35dacc8fa

bundle install --without production

 

8/8 firebase

https://app.codegrid.net/entry/2017-firebase-basic-1

 

http://tekumemo.blog.jp/archives/5891928.html

https://arrown-blog.com/firebase-javascript-hosting/

 

デプロイしても反映されないのキャッシュの削除で解決

 

https://arrown-blog.com/firebase-javascript-hosting/#Firebase_CLIWeb

https://html5experts.jp/technohippy/18040/

 

CSSが反映されなかった原因

アセットパイプライン

https://qiita.com/hogehoge1234/items/9a94ebc93c5f937502cd

git commit -amではなく

git add -Aでやる

rake assets:precompile RAILS_ENV=production

 

8/9 プロジェクトごとのホスティングの方法

Firebase

Firebase.jsonをフォルダごとで分ける

 

Titleの左のアイコン設定 favicon

https://qiita.com/ntkgcj/items/6643a07a43a36029dc9b

 

8/10

チャットサイトですよ。サンプル

https://codelabs.developers.google.com/codelabs/firebase-web/index.html#1

現在の閲覧者の表示

https://www.webtoolnavi.com/real-time-user/

 

 

Mac ショートカットキー

 

ウィンドウしまう

command+M

 

ウィンドウ閉じる

command+W

 

SS

Shift+command+3or4

 

8/13

https://qiita.com/n0bisuke/items/d3cb6bd7a763d6cf69dd

 

POSTGET

GETURLに付加してリクエストします ブックマークできる

  • GET: /foo/bar?p=........&u=.........

POSTBodyに含めてリクエストします。ブックマークできない

  • POST: /foo/bar
  • param:p:...........,u.........

GETURLに直接付加するので目でパラメータを見ることができます。
POST
Bodyに含めるので目で見ることはできません。

GETは目に見えるけど、POSTは見えないから安全と言う人がたまにいますが、これは間違いです。目に見えてないだけです。通信を盗聴されればどちらにも差はありません。

 

Node.js = サーバサイドJavaScript

https://eng-entrance.com/what-is-nodejs

「クライアントもサーバサイドも同じ言語で書けたら楽じゃない?」

 

fatal: remote origin already exists.の対処

http://pyoonn.hatenablog.com/entry/2014/10/29/191744

git remote rm origin

 

 

Firebase コマンド

firebase serve

firebase deploy