2016-09-09 8 views
0

:誰でもすることができますようRailsの5つのフィルタフィールドので、Railsのコンソールで、私はこのように行を作成してい

params = {:question=>"33333", :explanation=>"333", :hint=>"333", :worth=>1, :tags=>"3333", :active=>true, :qtype=>true, :user_id=>4} 

q = Question.create! params 

SQL (3.2ms) INSERT INTO "questions" ("user_id", "question", "explanation", "hint", "tags", "worth", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING "id" [["user_id", 4], ["question", "33333"], ["explanation", "333"], ["hint", "333"], ["tags", "3333"], ["worth", 1], ["created_at", 2016-09-09 20:45:51 UTC], ["updated_at", 2016-09-09 20:45:51 UTC]] 

が見るには、「アクティブ」と「QTYPE」のフィールドは、Railsのによってフィルタリングされています。どちらのカラムも、移行ファイルとPostgreSQLのテーブルに存在します。モデルはかなり基本的です:

class Question < ApplicationRecord 
    belongs_to :user 
    has_many :answer 

    default_scope { order('id DESC') } 

    validates :question, presence: true 
end 

私はなぜこれらのフィールドをフィルタリングするのか分かりません。私はschema.rbファイルを削除し、ゼロからデータベースを作成しましたが、エラーは継続します。

答えて

1

以前は、PostgreSQLのNULL値を持つブール値がレールによって正しく設定されていないという問題が報告されています。

デフォルト値でフィールドを再作成すると解決するはずです。 ...ちなみに

add_column :questions, :active, :boolean, default: false 
add_column :questions, :qtype, :boolean, default: false 

、ライン...と再作成当時の移行をロール、および

has_many :answer 

おそらくする必要があります...

has_many :answers 
関連する問題