2016-10-18 6 views
0

データベースに配列を挿入しようとしています。パラメータには配列(ステータス "=" {group_one "=>" one "、" group_two "=>" One "})が表示されますが、inot dbを挿入している間は省略されています。ハッシュをデータベースに挿入しない

以下が表示されます。ここでは

Parameters: {"utf8"=>"✓", 
"authenticity_token"=>"JgCBl8vcDAP9AUGaylk34om4mbKkxHCgM+GuAfxTL3sywaJkmvKL3pyS2C44MAkzMZ6AK+CUVv/Vmg9aUQYrZw==", 
"irb"=>{"proposalno"=>"", "otherapptype"=>"", "titleofproject"=>"", 
"date1"=>"", "date2"=>"", "date3"=>"", "fundingdetails"=>"", 
"fund"=>"No internal funds or external funds are requested", 
"datetobegindc"=>"", "rationale"=>"", "abstract"=>"", 
"noofsub"=>"0", "natureofassociation"=>"", 
"subjectselection"=>"", "confidentiality"=>"", 
"howwhereconsent"=>"", "methodproceduresubjectparti"=>"", 
"childrenpermission"=>"", "infowithheld"=>"", 
"riskbenefitratio"=>"", "minimizingrisk"=>""}, 
"status"=>{"group_one"=>"One", "group_two"=>"One"}, 
"responsibility"=>{"nameoffac"=>"", "nameofinv"=>"", 
"deptoffac"=>"", "deptofinv"=>"", "addoffac"=>"", 
"addofinv"=>"", "phoneoffac"=>"", "phoneofinv"=>"", 
"emailoffac"=>"", "emailofinv"=>""}, "commit"=>"SUBMIT MY DETAILS"} 
    (0.2ms) begin transaction 
    SQL (2.9ms) INSERT INTO "irbs" ("proposalno", "titleofproject", 
"date1", "date2", "date3", "fund", "fundingdetails", "datetobegindc", 
"rationale", "abstract", "noofsub", "natureofassociation", 
"subjectselection", "confidentiality", "howwhereconsent", 
"methodproceduresubjectparti", "childrenpermission", "infowithheld", 
"riskbenefitratio", "minimizingrisk", "otherapptype", "created_at", 
"updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 
?, ?, ?, ?, ?, ?) [["proposalno", ""], ["titleofproject", ""], 
["date1", ""], ["date2", ""], ["date3", ""], 
["fund", "No internal funds or external funds are requested"], 
["fundingdetails", ""], ["datetobegindc", ""], ["rationale", ""], 
["abstract", ""], ["noofsub", "0"], ["natureofassociation", ""], 
["subjectselection", ""], ["confidentiality", ""], 
["howwhereconsent", ""], ["methodproceduresubjectparti", ""], 
["childrenpermission", ""], ["infowithheld", ""], 
["riskbenefitratio", ""], ["minimizingrisk", ""], 
["otherapptype", ""], ["created_at", 2016-10-18 19:48:35 UTC], 
["updated_at", 2016-10-18 19:48:35 UTC]] 

は私のコントローラである:ここでは

class IrbsController < ApplicationController 

    def new 
    @irb = Irb.new 
    end 



    def create 
    @irb = Irb.new(irb_params) 
    if @irb.save 
     #RegistrationMailer.signup_confirmation(@registration).deliver 
     #log_in @user 
     flash[:success] = "Your details have been registered. A confirmation email has been sent." 
     redirect_to root_url 
    else 
     render 'new' 
    end 
    end 

    def index 
    end 

    def edit 
    end 

    def show 
    end 

    private 
    def irb_params 
     params.require(:irb).permit(:proposalno, :apptype, :titleofproject, :acc1, :date1, :acc2, :date2, :acc3, :date3, :projtype, :fund, :fundingdetails, :datetobegindc, :statusofprininv, :typeofreview, :rationale, :abstract, :noofsub, :assowithsub, :natureofassociation, :subjectselection, :ressubcomp, :adforresparti, :confidentiality, :voluntaryparticipation, :howwhereconsent, :methodproceduresubjectparti, :childrenpermission, :infowithheld, :risk, :riskbenefitratio, :minimizingrisk, :otherapptype, status:[]) 
    end 
end 

移行です:

class CreateIrbs < ActiveRecord::Migration[5.0] 
    def change 
    create_table :irbs do |t| 
     t.string :proposalno 
     t.text :status 
     t.string :responsibility 
     t.string :apptype 
     t.string :titleofproject 
     t.string :acc1 
     t.string :date1 
     t.string :acc2 
     t.string :date2 
     t.string :acc3 
     t.string :date3 
     t.string :projtype 
     t.string :fund 
     t.string :fundingdetails 
     t.string :datetobegindc 
     t.string :statusofprininv 
     t.string :typeofreview 
     t.string :rationale 
     t.string :abstract 
     t.string :poputype 
     t.string :noofsub 
     t.string :assowithsub 
     t.string :natureofassociation 
     t.string :subjectselection 
     t.string :ressubcomp 
     t.string :adforresparti 
     t.string :confidentiality 
     t.string :voluntaryparticipation 
     t.string :howwhereconsent 
     t.string :methodproceduresubjectparti 
     t.string :childrenpermission 
     t.string :infowithheld 
     t.string :risk 
     t.string :riskbenefitratio 
     t.string :minimizingrisk 
     t.string :otherapptype 
     t.timestamps 
    end 
    end 
end 

モデルタラE:

class Irb < ApplicationRecord 
    serialize :status 
end 
+1

あなたは、誰もがここで私は私のコントローラのコードを追加 –

+0

@CdotStrifeVIIあなたを助けることができる前に、詳細を追加する必要があります。見てください。 – Sujith

+0

おそらく私だけですが、パラメータリストに配列が見つかりません。あなたの配列の名前はどうですか? – spickermann

答えて

0

stringからあなたのデータ型を変更してみてください。 short-Hashの違いは、キーと値の集合で構成されています。

okomikerukoで述べたように、テキストデータ型の列を定義する方がよいでしょう。私はここで255文字以上とは思っていませんが、少なくともあなたの質問にある例では。

私は問題があなたのpermitメソッドの中にあると信じています。 :status:という名前のキーの場合、ハッシュで許可されている0個のキーを定義します。それが問題の原因です。

あなたが知っている場合は、..., status: [:group_one, ...]のキーを指定する必要があります。また、動的である場合は、下のリンクで見つけることができる別のソリューションを使用する必要があります。

https://github.com/rails/rails/issues/9454

Rails4: How to permit a hash with dynamic keys in params?

+0

ありがとうございました。私は私の見解で小さな誤りを発見し、それを修正しました。 – Sujith

+0

私はそれが助けてうれしいです。 – rudkovskyi

関連する問題