0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

rails 発展その5 カラムの追加 単語の区切り 文字数制限

Posted at

細かい知識を得たので投稿します。

カラムの追加

ターミナル
  $ rails g migration AddIntroductionToテーブル名 追加したいカラム名:データ形式
例
  $ rails g migration AddIntroductionToItems introduction:string

  マイグレーションファイルが作成されるので

 $ rake db:migrate

スネークケースとキャメルケース

プログラムが単語の区切りを認識する際、2通りの方法があります。
スネークケースは、例えば「sample_yes_no」のように「_」で単語を区切る方法です。
キャメルケースは、「SampleYesNo」のように単語の頭文字を大文字にすることで単語を区切ります。

inputのヘルパーメソッド text_field:maxlengthオプション

inputの文字数制限を起こすオプションです。

html
<div >
    <%= f.text_field :name, autofocus: true, maxlength: "6" %>
</div>
<!--これで文字数が6文字制限になります。-->
0
2
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
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?