이 사용자 작업이 주어지면 :
class UsersController < ApplicationController
respond_to :html, :js
def update
@user = User.find(params[:id])
# do stuff...
respond_with(@user)
end
#other functions
end
내 app/views/users/update.js.erb
파일에 응답을 어떻게 인쇄 합니까?
거기에서 @user 변수에 액세스 할 수 있지만 "상태"또는 성공 여부는 어떻게 알 수 있습니까?
내 현재 app/views/users/update.js.erb
파일은 다음과 같습니다.
console.log("update?");
console.log("<%=@user %>");
인쇄 :
udate?
#<User:0x639a470>
콘솔에서.
기본적으로 @user로 작업을 시도하기 전에 성공했는지 알고 싶습니다.
사용하다:
console.log("<%[email protected]_json%>");
def update
@user = User.find(params[:id])
# do stuff...
if @user.save
# user update was successful
respond_with(@user)
else
flash[:error] = "User Update Failed"
render :action => "some_action"
end
end
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다