0
私はアプリケーションのモデルに多くの文字列を持ちますが、各行に先頭、末尾および重複する空白は入れてはいけません。Railsの標準属性セッターを生成する方法
これを確実にするために、私は、属性ごとに別々の属性setterメソッドを作成しました:
def label=(text)
write_attribute(:label, text.strip.squeeze(' '))
end
def description=(text)
write_attribute(:description, text.strip.squeeze(' '))
end
...
よりエレガント、ドライヤーの道があるはずです。 nilのチェックを含む。