Provide bracket-method `[]` for ActiveRecord Class
OTHER License
Provide bracket-method []
to index-like access for ActiveRecord Class. It method is a syntax-sugar of find_by_slug
(dynamic-finder of ActiveRecord).
Add this line to your application's Gemfile:
gem 'activerecord-bracket'
And then execute:
$ bundle
Or install it yourself as:
$ gem install activerecord-bracket
(Japanese)
@zonu_exe
のようにユーザを識別するために使用される) と、変更不可能でアカウント作成時に自動で付番される(10進整数のみからなる) ID が存在しますActiveRecord::Bracket
においてもその制限はModelのvalidationのみに依存します(Japanese)
slug
列を用意します (カラム名の制限は撤廃予定です)
find_by_slug
の構文糖でしかないことに留意しないと想定外の挙動をするおそれがある)# define system supported language
Language.create(name: 'Japanese', slug: 'ja')
Language.create(name: 'English' , slug: 'en')
# get Language instance object
ja = Language[:ja] #=> #<Language id: 1, name: "Japanese", slug: "ja">
en = Language[:en] #=> #<Language id: 2, name: "English", slug: "en">
# filter non-supported languages
ko = Language[:ko] #=> nil
fr = Language[:fr] #=> nil
# sanitize
errorkeystr = 'kimiha jitsuni baka dana'
_ = Language[errorkeystr] #=> nil
(Japanese)
Model.[]
の引数は String
, Symbol
のどちらでもActiveRecordがよしなに扱ってくれます。たぶん。git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)