rale db:resetとrake db:migrate:reset

メモ。railsのdb周りがあまりよくわかっていない。

http://railstutorial.jp/chapters/updating-showing-and-deleting-users?version=4.0#sec-sample_users

チュートリアルでサンプルユーザーを大量に作るRakeタスクを作ったが、記載通りのbundle exec rake db:resetだとうまくいかず、bundle exec rake db:migrate:reset だとうまくいく。

前者だとdbの中身が消えていなかったので、同じメールアドレスを持つユーザーをRakeタスクで作ろうとして、失敗しているのでは、という予想。

ただその場合に例外も何も吐かないのが気になる・・・

rspecの中でデバッグ

rspecがこけたときに変数の中身を確認したい場合がある。

pry-debuggerを使えばよいらしい。

http://kazusan85.hatenablog.com/entry/2014/09/02/pry-debugger%E3%81%8C%E3%81%A8%E3%81%A6%E3%82%82%E4%BE%BF%E5%88%A9

http://kazusan85.hatenablog.com/entry/2014/09/03/rspec%2BCapybara%E3%81%A7%E3%83%93%E3%83%A5%E3%83%BC%E3%81%AE%E3%83%86%E3%82%B9%E3%83%88%E3%82%92%E6%9B%B8%E3%81%8F%E3%81%A8%E3%81%8D%E3%81%AE%E3%83%87%E3%83%90%E3%83%83%E3%82%B0

Railsにページを追加

どんなファイルをいじってるかまとめ

$ git diff --cached
diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb
index 19f79a9..d304760 100644
--- a/app/controllers/static_pages_controller.rb
+++ b/app/controllers/static_pages_controller.rb
@@ -7,4 +7,7 @@ class StaticPagesController < ApplicationController
 
   def about
   end
+
+  def contact
+  end
 end
diff --git a/app/views/static_pages/contact.html.erb b/app/views/static_pages/contact.html.erb
new file mode 100644
index 0000000..18967b3
--- /dev/null
+++ b/app/views/static_pages/contact.html.erb
@@ -0,0 +1,6 @@
+<% provide(:title, 'Contact') %>
+<h1>Contact</h1>
+<p>
+ Contact Ruby on Rails Tutorial about the sample app at the
+ <a href="http://railstutorial.jp/contact">contact page</a>.
+</p>
diff --git a/config/routes.rb b/config/routes.rb
index 134f94a..ed5cc87 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -2,6 +2,7 @@ SampleApp::Application.routes.draw do
   get "static_pages/home"
   get "static_pages/help"
   get "static_pages/about"
+  get "static_pages/contact"
   # The priority is based upon order of creation: first created -> highest priority.
   # See how all your routes lay out with "rake routes".
 
diff --git a/spec/requests/static_pages_spec.rb b/spec/requests/static_pages_spec.rb
index 24355cb..a93fa32 100644
--- a/spec/requests/static_pages_spec.rb
+++ b/spec/requests/static_pages_spec.rb
@@ -42,4 +42,16 @@ describe "StaticPages" do
     end
   end
 
+  describe "Contact page" do
+    it "should have the content 'Contact'" do
+        visit '/static_pages/contact'
+        expect(page).to have_content('Contact')
+    end
+
+    it "should have the title 'Contact'" do
+        visit '/static_pages/contact'
+        expect(page).to have_title("Ruby on Rails Tutorial Sample App | Contact")
+    end
+  end
+
 end

Go言語によるWebアプリケーション開発メモ(1)

1.4.1
パッケージのエクスポートの有無は先頭が大文字か小文字かで判断。
大文字ならエクスポートされる。

...interface{}は、任意の方の引数を何個でも(ゼロ個も可)受け取る。Goの標準ライブラリでよくみかける。

WEBrick

そういやなにもサーバーの設定していないのにwebページみれたりしてるなーと思っていたら、railsやるとこのような出力が。

```
=> Booting WEBrick
=> Rails 4.0.5 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2016-04-11 01:02:27] INFO WEBrick 1.3.1
[2016-04-11 01:02:27] INFO ruby 2.0.0 (2014-05-08) [x86_64-darwin14.0.0]
[2016-04-11 01:02:27] INFO WEBrick::HTTPServer#start: pid=93181 port=3000
```

どうやらデフォルトだとWEBrickなるもので動くらしい。
https://thinkit.co.jp/article/117/1

後で読む