https アクセス(自己署名証明書) ; Rails
継続遷移には材料不足ではあるが、ものを揃えるだけならば
前提
http://mat5ukawa.hateblo.jp/entry/2014/02/28/005347
で自己署名証明書を作成していること
thin
install gem
$ gem install thin
rails s -p 3000 の代わりに次を叩く
Terminal 甲 $ thin start -p 3000 Terminal 乙 $ thin start -p 3001 --ssl --ssl-verify --ssl-key-file ~/.ssl/server.key --ssl-cert-file ~/.ssl/server.crt
ssl_force
準備
モデル設計に意味は無し
$ rails g controller top index $ rails g Book title:string $ rake db:migrate
app/controller/top_controller.rb
class TopController < ApplicationController def index end end
app/views/top/index.html.erb
<%= link_to 'Go to books library', controller: :books, action: :index, only_path: false, protocol: 'https://' %>
app/controller/book_controller.rb
class BooksController < ApplicationController before_action :set_book, only: [:show, :edit, :update, :destroy] force_ssl if: :ssl_configured? ... private def ssl_configured? Rails.env.development? # valid in development. If deploy, change to Rails.env.production? end end
https://localhost:3001/books 安全性確認
https://localhost:3001/books 例外追加後
情報元 # thanks
Stuff I've Learned About Ruby on Rails: Running a rails server to support SSL