スポンサーリンク

PhoenixTutorialを写経(2)

前回は、以下を写経した

https://daruiapprentice.blogspot.jp/2015/06/rails-tutorial-for-phoenix_20.html

http://twosquirrel.mints.ne.jp/?p=14852

今回は、引き続き、以下を写経する

2015年6月21日
[Rails Tutorial for Phoenix]Static pages
https://daruiapprentice.blogspot.jp/2015/06/rails-tutorial-for-phoenix_21.html

(参考)RailsTutorial 第3章
https://railstutorial.jp/chapters/static_pages?version=5.0#cha-static_pages

(環境)
Windows 8.1
VirtualBox 5.1.14
Vagrant 1.9.1
CentOS7.3
Erlang/OTP 19
Elixir 1.3.4
Phoenix 1.2.1

環境構築は以下のように行っている

http://twosquirrel.mints.ne.jp/?p=14421

http://twosquirrel.mints.ne.jp/?p=14545

(0)Windows(ホストOS)のコマンドプロンプトで、vagrant upして、TeraTermでログイン(127.0.0.1, 2222, vagrant, vagrant)

image_thumb image

(1)Preparation

cd /vagrant
mix phoenix.new sample_app
cd sample_app
npm install --no-bin-links
node node_modules/brunch/bin/brunch build
mix ecto.create
mix phoenix.server

image image

image image

●Git管理して、Bitbucketに登録。(面倒なので、やらなくてよいかも。。。)

bitbucuket.orgで、sample_app_p という新規レポジトリを作成

image image

bitbucketに登録の準備は以下を参照(面倒になってしまった。。。)

http://twosquirrel.mints.ne.jp/?p=14127

sudo yum -y install git
git init
git add -A
git commit -m "Initialize repository"

ssh-keygen -f ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub

出てきた文字列をコピーして、Bitbucketにログインして、アカウント > SSHキー で、SSHキーを登録。

git push -u origin master

image

git checkout -b static_pages
git branch

image

(2)Add route

web/router.ex
mix phoenix.routes

image

(3)Create Controller

web/controllers/static_pages_controller.ex (New)

image

(4)Create view & template

web/views/static_pages_view.ex (New)

image

web/templates/static_pages ディレクトリの作成

web/templates/static_pages/home.html.eex

image

web/templates/static_pages/help.html.eex

image

mix phoenix.server

image

なんかエラー

web/controllers/static_pages_controller.ex の2行目の、

use SampleApp.Web, :controller

の、「,」(カンマ)が抜けていた。

image

訂正してから、再度、mix phoenix.server

http://localhost:4000/home
http://localhost:4000/help

image image

(5)Add about page

web/router.ex

image

web/controllers/static_pages_controller.ex

image

web/templates/static_pages/about.html.eex

image

http://localhost:4000/about

image

(6)Little dynamic

web/controllers/static_pages_controller.ex

image

web/templates/static_pages/home.html.eex

image

web/templates/static_pages/help.html.eex
web/templates/static_pages/about.html.eex も同様に。

image image

http://localhost:4000/about

image

Ctrl+C を2回でサーバ停止。

(7)git

git add .
git commit -am "Finish static_pages."
git checkout master
git merge static_pages
git push -u origin --all

image image

スポンサーリンク