私はReactJS(リアクションレール)+ Railsアプリケーションを構築しています。私は自分自身(まだ)ReactJSの開発者ではなく、ReactJSが選ばれた後にプロジェクトに取り込まれました。ReactJS + Rails:HABTMは属性にないため、保存することができません。
私の問題は、投稿リクエストの作成と編集を介してReact to Railsから送信されるパラメータに関するものです。この場合の マイモデル:
class Hrfile < ActiveRecord::Base
mount_uploader :attachment, AttachmentUploader
has_and_belongs_to_many :sras
...
end
class Sra < ActiveRecord::Base
...
has_and_belongs_to_many :hrfiles
...
validates :name, presence: {message: "Please input a name"}
end
ReactJSは、私が使用したフォームとしてFormsyが反応して反応選択Formsyのマッピング要求に応えるために複数選択形式のように変更使用しています。
次のデータがReactJSから送信されている経由の.post( '/ SRAS')を反応させ、(データ)を送信:。
{
active:null
address:null
asset_id:null
assetother:null
brand_id:null
city:null
conclusion:"Test conclusion"
country_id:null
enddate:null
hrfile_ids:["2","1"]
indicator_deteroriation:null
ireport_ids:null
name:"Test assessment"
organisation_id:null
region_id:null
reviewdate:null
startdate:null
treatment:null
user_id:null
}
私は把握できないという問題/バグ、IでありますReactJSアプリケーションを使用して名前とX番号のHrfilesを含む新しいSraを作成し、JSONを投稿します(上記のように)。これはRailsが受け取ったものです:
Started POST "/sras" for 127.0.0.1 at 2016-04-05 16:29:07 +0800
Processing by SrasController#create as JSON
Parameters: {"name"=>"Test assessment", "organisation_id"=>nil, "brand_id"=>nil, "user_id"=>nil, "asset_id"=>nil,
"startdate"=>nil, "reviewdate"=>nil, "address"=>nil, "city"=>nil, "region_id"=>nil, "country_id"=>nil, "assetother"=>nil, "enddate"=>nil, "active"=>nil, "treatment"=>nil,
"indicator_deteroriation"=>nil, "conclusion"=>"Test conclusion", "ireport_ids"=>nil, "hrfile_ids"=>["2","1"],
"sra"=>{"name"=>"Test assessment", "organisation_id"=>nil, "country_id"=>nil, "user_id"=>nil,
"startdate"=>nil, "enddate"=>nil, "reviewdate"=>nil, "active"=>nil, "city"=>nil, "address"=>nil, "asset_id"=>nil, "assetother"=>nil,
"indicator_deteroriation"=>nil, "conclusion"=>"Test conclusion", "brand_id"=>nil, "region_id"=>nil}}
ReactJSアプリは、転送します。 "hrfile_ids" => ["2"、 "1"]しかし、ParamsWrapper(私が思う)は属性として 'hrfile_ids'を認識せず、名前は保存されるだけです。
誰かが私がここで何が欠けているのか考えていますか?
他のコードブロックや詳細が必要な場合は教えてください。 「SRA」オブジェクトは、Railsの中でparams wrapperによって作成された指摘で
EDITジェスパーに
おかげ - あなたは事前に:)感謝を助けることができると思います。私は@ sra.hrfilesを呼び出して所属するHrfilesを呼び出すことができる2つのモデルSraとHrfileの間に関係がありますが、hrfile_idsパラメータをJSONにラップすることはまだできません。
この@thejsprのおかげで!私は今、電話で 'params.require(:sra).merge(hrfile_ids:params [" hrfile_ids "])' をSrasController#sras_params :)でハックします。 – sstubben