중첩 된 해시를 반복하여 두 개의 개별 필드에 액세스하려고합니다.Rails4는 중첩 된 매개 변수 해시를 통해 반복합니다.
- 확인 후 내가
@point_of_interest
에 update 메소드를 호출 할 :is_cover_photo
에 해당하는 경우:is_cover_photo
에 해당하는 경우 볼이 내가 할 노력하고 있어요 것입니다.
오류가 계속 발생하여이 작업을 수행하는 방법을 알 수 없습니다.
{"utf8"=>"✓",
"_method"=>"patch",
"authenticity_token"=>"XGvgfxFHZKpiE8eGqc+55qOlSSk9LYFGdywWyABezXo=",
"point_of_interest"=>{"title"=>"WolfieOne",
"latitude"=>"33.577836",
"longitude"=>"-85.074692",
"caption"=>"CaptionOne",
"website"=>"google.com",
"summary"=>"This is a test summary.",
"albums_attributes"=>{"0"=>{"title"=>"Album Uno",
"cover_photo"=>#<ActionDispatch::Http::UploadedFile:0x000000113ae4c0 @tempfile=#<Tempfile:C:/Users/Samuel/AppData/Local/Temp/RackMultipart20140220-7188-4ptfo1>,
@original_filename="Lighthouse.jpg",
@content_type="image/jpeg",
@headers="Content-Disposition: form-data; name=\"point_of_interest[albums_attributes][0][cover_photo]\"; filename=\"Lighthouse.jpg\"\r\nContent-Type: image/jpeg\r\n">,
"is_cover_photo"=>"1",
"id"=>"23"},
"1"=>{"title"=>"Album 2",
"is_cover_photo"=>"0",
"id"=>"24"},
"2"=>{"title"=>"The Best Album Alive",
"is_cover_photo"=>"0",
"id"=>"30"}}},
"commit"=>"Submit Wolfie",
"id"=>"15"}
이에 어떤 도움 : 여기
def update
@point_of_interest = PointOfInterest.find(params[:id])
if @point_of_interest.update(params[:point_of_interest].permit(:title, :caption, :website, :summary, :latitude, :longitude, :cover_photo, albums_attributes: [:id, :cover_photo, :title, :is_cover_photo]))
params[:point_of_interest][:albums_attributes].each do |key, value|
value.each do |k, v|
if k[:is_cover_photo] && k[:cover_photo].blank?
@point_of_interest.update(:cover_photo => k[:cover_photo])
end
end
end
redirect_to @point_of_interest
else
render 'edit'
end
end
이 전달되는 매개 변수입니다 :
"no implicit conversion of Symbol into Integer"
이 point_of_interests_controller
내 update
방법에 있습니다
이
내가 점점 오전 오류입니다 대단히 감사하겠습니다. 업데이트이
나를 위해 문제를 해결 :
params[:point_of_interest][:albums_attributes].each do |key, value|
if value[:is_cover_photo] && value[:cover_photo].present?
@point_of_interest.update(:cover_photo => value[:cover_photo])
end
end
redirect_to @point_of_interest
편집 : 감사
params[:point_of_interest][:albums_attributes].each do |key, value|
if value[:is_cover_photo] && value[:cover_photo].present?
@point_of_interest.update(:cover_photo => value[:cover_photo])
end
end
어떤 라인에서 오류가 발생합니까? – tyler
k [: is_cover_photo] && k [: cover_photo] .blank? – EighthEmperor
죄송합니다. 그 말을 잊어 버렸습니다. – EighthEmperor