2017-03-14 6 views
0

HSTore 매개 변수가 데이터베이스에 저장되지 않은 경우 큰 형식을 저장할 때 무슨 일이 벌어지는 지 이해하기가 힘듭니다. 누군가 내가 명백한 오류라고 추정하는 것을 지적 할 수 있습니까? (나는 빨리 가능한 한 간결하게 유지하기 위해 많은 양의 출력을 손질했습니다.Rails 4.2.5, simple_form, hstore, 중첩 된 양식 - Hstore Hash가 저장시 지속되지 않음

아무 콘솔 출력이 없다, 그것은 허가되지 않은 PARAMS 또는 아무것도에 대해 불평 아니에요. equipment 필드를 discipline 모델이 hstore 열입니다.

을 감안할 때 내 강력한 PARAMS 설정 :

params.require(:profile).permit(
    :id, 
    :user_id, 
    :gender, 
    :dob, 
    ..snip.. 
    disciplines_attributes: [ 
    :id, 
    :profile_id, 
    :discipline_type, 
    :distance_in_meters_per_week, 
    ..snip.. 
    :equipment => [ 
     :time_trial_bike, 
     :road_bike, 
     :turbo_trainer, 
     :watt_bike 
    ] 
    ] 

내 PARAMS :

다음
Parameters: {"utf8"=>"✓", "authenticity_token"=>"XX", "profile"=> 
{"gender"=>"male", "dob(1i)"=>"1927", "dob(2i)"=>"3", "dob(3i)"=>"14", 
"disciplines_attributes"=>{"0"=> 
{"discipline_type"=>"swimming", "distance_in_meters_per_week"=>"", 
"equipment"=> 
    { 
     "pull_buoy"=>"true", 
     "paddles"=>"false", 
     "wetsuit"=>"true", 
     "fins"=>"false", 
     "tempo_trainer"=>"false" 
    }}}, 
"commit"=>"Create Profile"} 

내 inspecte

{"gender"=>"male", "dob(1i)"=>"1927", "dob(2i)"=>"3", "dob(3i)"=>"14", "height_in_meters"=>"", 
"disciplines_attributes"=>{"0"=>{"discipline_type"=>"swimming", "distance_in_meters_per_week"=>"", 
"equipment"=>{ 
    "pull_buoy"=>"true", 
    "paddles"=>"false", 
    "wetsuit"=>"true", 
    "fins"=>"false", 
    "tempo_trainer"=>"false"}} 
} 

누군가가 장비의 해시가 데이터베이스에 커밋되지 않는 이유 나를 이해하는 데 도움이 : 컨트롤러에서 D 결과 profile_params?

Discipline id: 148, profile_id: 50, discipline_type: "running", distance_in_meters_per_week: "", sessions_per_week: nil, time_per_session_in_minutes: nil, created_at: "2017-03-14 12:02:15", updated_at: "2017-03-14 12:02:15", equipment: nil>] 

답변

0

자신의 질문을 쓰는 것이 무엇인가요? 그러면 언제나 당신이 결국 다른 곳에서 실수 한 것을 결국 이해하게됩니다.

Disciplines::initialize 메서드를 오버로드하여 새 레코드 인 경우 장비 hstore에 '시드'합니다. 그러나 새로운 기록뿐만 아니라 모든 경우에 그것을 수행하십시오.

내 자신의 질문에 대한 답변입니다. 위의 작업을 수행하고, 차라리 콘솔에 의존하지 않고, 직접 DB를 확인 귀찮게 더라면, 그 실현 될 수 있습니다

after_initialize :setup_equipment 

def initialize(search, options = {}) 
    self.options = options 
    super 
end 

private 

def setup_equipment 
    self.equipment = self.options 
end 

모두 함께 내 문제였다. :(