LoginSignup
20
21

More than 5 years have passed since last update.

Rails でテキストエリアのデフォルトの行数・列数を変更する

Posted at
= form_for @post do |f|
  = f.text_area :body

みたいなコードで生成される textarea の cols, rows はデフォルトでは 40, 20 になる。個人的には rows 多すぎ。

= f.text_area :body, rows: 10

と書けば上書きできるけど、デフォルトを変えたい。

actionpack-3.2.8/lib/action_view/helpers/form_helper.rb をみると下記の定数があり、これを使用している。

DEFAULT_TEXT_AREA_OPTIONS = { "cols" => 40, "rows" => 20 }

なので config/initializers/form_helper.rb あたりにファイルを作って、下記のコードを書けばよい。

ActionView::Helpers::InstanceTag::DEFAULT_TEXT_AREA_OPTIONS.merge!("rows" => 10) 
20
21
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
21