사용자가 프로필 아바타를 변경할 때 부분 렌더링을 시도하고 있습니다 (페이지 다시로드와 반대). 문제는 .js.erb 파일이 전혀 트리거되지 않는 것 같습니다 (내 콘솔 로그 메시지가 인쇄되지 않음). 단순히 페이지를 루트로 리디렉션하기 때문에 오류가 발생하지 않는 것 같습니다.
내 서버 로그 (아래 참조)에 토큰 인증 오류가 있지만 인증을 비활성화하고 오류가 사라지더라도 리디렉션이 계속 발생하고 .js.erb는 본질적으로 무시됩니다.
Processing by UsersController#update as HTML
Parameters: {"utf8"=>"✓", "user"=>{"avatar"=>#<ActionDispatch::Http::UploadedFile:0x007f9ae101c3f8 @tempfile=#<Tempfile:/tmp/RackMultipart20140716-9847-v0ray3>, @original_filename="creator.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"user[avatar]\"; filename=\"creator.jpg\"\r\nContent-Type: image/jpeg\r\n">}, "commit"=>"Upload Avatar", "id"=>"2"}
Can't verify CSRF token authenticity
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 2 ORDER BY "users"."id" ASC LIMIT 1
(0.0ms) begin transaction
(0.1ms) commit transaction
User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", "2"]]
(0.0ms) begin transaction
User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 2]]
SQL (0.1ms) UPDATE "users" SET "avatar" = ?, "updated_at" = ? WHERE "users"."id" = 2 [["avatar", "creator.jpg"], ["updated_at", Wed, 16 Jul 2014 14:41:14 UTC +00:00]]
(160.8ms) commit transaction
Redirected to http://localhost:3000/
.js.erb 파일
$(".avatar-container").html("<%= escape_javascript(render(:partial => 'profile/avatarContainer')) %>");
사용자 컨트롤러
def update
@user = User.find(params[:id])
respond_to do |format|
if @user.update_attributes(params.require(:user).permit!)
format.js
format.html{
redirect_to root_path
}
else
format.js
format.html{redirect_to root_path}
end
end
end
부분 :
-if current_user.avatar.url != "/assets/userProfile_dashboard.png"
.avatar-large
=image_tag current_user.avatar.url
= simple_form_for(current_user, html: {:multipart => true }, remote: true) do |f|
= f.file_field :avatar, style:"margin-top:-258px;", id: "profile-avatar"
= f.button :submit, "Upload Avatar", :class => "buttonRoundedCornersGreen ", style: "width:130px;margin-top:20px;", id: "avatar-submit"
-else
.no-avatar
= simple_form_for(current_user, html: {:multipart => true }, remote: true) do |f|
= f.file_field :avatar, id: "profile-avatar"
편집 : 많은 검색 후 파일 업로드에 대해 다중 부분이 true이고 원격 true가 충돌 을 일으키는 것으로 나타납니다 . Remotipart gem 을 설치하여이 문제를 해결할 수있었습니다 .
많은 검색 후 파일 업로드에 대해 다중 부분이 true이고 원격 true가 충돌 을 일으키는 것으로 보입니다 . Remotipart gem 을 설치하여이 문제를 해결할 수있었습니다 .
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다