質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

1回答

712閲覧

Railsのテーブルに関しての質問です!

kou_action

総合スコア8

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2018/03/17 05:50

rails generate controller モデル名 カラム名:データ型のコマンドを
利用して、Productモデルを作成しようと思うんですが、作成するにあたって疑問に思う点があったので、
質問させて頂ければと思います。

カラム名は、available_onで
available_onのデータ型は、datetime(0,0)と指定したい場合、
rails g controller Product available_on:datetime(0,0)
と入力すればいいのでしょうか?
(0,0)とdatetimeの後ろに入力するのは、初めて見たので!
oaRails初心者ですが、教えて頂ければ幸いです。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

参考情報

  • API リファレンス

http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-add_column

...
The type parameter is normally one of the migrations native types, which is one of the following: :primary_key, :string, :text, :integer, :bigint, :float, :decimal, :numeric, :datetime, :time, :date, :binary, :boolean.
...
Available options are (none of these exists by default):

:limit - Requests a maximum column length. This is the number of characters for a :string column and number of bytes for :text, :binary and :integer columns.
:default - The column's default value. Use nil for NULL.
:null - Allows or disallows NULL values in the column. This option could have been named :null_allowed.
:precision - Specifies the precision for the :decimal and :numeric columns.
:scale - Specifies the scale for the :decimal and :numeric columns.

...

  • 3.5 Column Modifiers

http://edgeguides.rubyonrails.org/active_record_migrations.html#column-modifiers

  • Advanced Rails model generators

https://railsguides.net/advanced-rails-model-generators/

...
The whole list of available types:

integer
primary_key
decimal
float
boolean
binary
string
text
date
time
datetime
timestamp

...
Set limit for field of integer, string, text and binary fields:
$ rails generate model user pseudo:string{30}

Special syntax to generate decimal field with scale and precision:
$ rails generate model product 'price:decimal{10,2}'
...

投稿2018/03/17 06:27

katoy

総合スコア22324

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問