Ich habe 2 Modell eine für Benutzer (amitians) andere about.rb ihre Details speichern sie eine has_one Beziehung zwischen ihnen, aber Problem ist, wenn ich ein neues über meine über Tabelle zu erstellen hat eine amitan_id = nullWarum wird meine Benutzer-ID auf null aktualisiert?
Als ich das gleiche in der rails-Konsole versuchte. Es funktioniert gut.
hier ist mein Code für die Modelle
About_amitians.rb
class AboutAmitian < ApplicationRecord
belongs_to :amitian
end
Amitian.rb
has_one :about_amitian , foreign_key: "amitian_id"
Mein AboutAmitian Controller
def new
@about_amitian = current_amitian.build_about_amitian
end
def create
@about_amitian = current_amitian.create_about_amitian!(about_amitian_params)
if @about_amitian.save
redirect_to :back
flash[:notice] = 'success'
else
render root_url
end
end
private
def about_amitian_params
params.require(:about_amitian).permit(:dob,:interest,:bio,:catch_phrase,:relationship_status)
end
In meinem Server-Logs Ich habe thi s Abfrage
Update 'about_amitians' set 'amitian_id' = NULL where 'about_amitian'.'id' = 1
andhere sind die params über Form
Parameters: {"utf8"=>"✓", "authenticity_token"=>"6MtQlOfl4kU1BPMDT81m8rwwxSYdaQKpUEZbvnFw9ux1nVELSTSmaRNOgUCKNyTe2VrrkY01Ewn70hGWn/9wQg==", "about_amitian"=>{"dob"=>"m", "interest"=>"vm", "bio"=>"blyhjb", "catch_phrase"=>"hjkl", "relationship_status"=>"bljhbl"}, "commit"=>"Create About amitian"}
'current_amitian' ist gesetzt?!? – Fallenhero
ya .. mit Gerät –
kann ich Params wissen, wenn Sie über hinzufügen? –