I have a Ruby Sinatra app and I have some code which I need to execute on all routes except for a few exceptions. How do I do this? If I wanted to execute the code on selected routes (whitelist style) I'd do this: ['/join', "/join/*", "/payment/*"].each do |path| before path do #some code end end How do I do it the other way round though (blacklist style)? I want to match all routes except '/join'
Rubyでは変数に代入を行う際に、右辺と左辺の式をカンマで区切ってやると、複数の変数への代入を1行で記述できる。 これは多重代入と呼ばれており、多重代入を使うことで変数の初期化を簡潔に書くことができる。 以下は変数aとbを、それぞれ1と2で初期化する例である。
複数のモデルにステータスなどの共通した値と処理を持たせたい!と思ってRails4.1のenumを使いつつ、concernなmoduleに切り出そうと思ったら、enumはActiveRecord所属だったので、困ってしまったときのメモ。 しょうがないので、ActiveRecordを継承したクラスを作ってそこに処理をまとめようとした。 class StatusRecord < ActiveRecord::Base before_create :set_status enum status: {draft: 0, published: 1} private def set_site self.status = some_helper_method end end class Article < StatusRecord ~snip~ end そしたら、statusってテーブルがねーよッ、というニ
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く