Reputation: 4413
Given this user action:
class UsersController < ApplicationController
respond_to :html, :js
def update
@user = User.find(params[:id])
# do stuff...
respond_with(@user)
end
#other functions
end
How do I print the response in my app/views/users/update.js.erb
file?
I can access the @user variable in there, but how do I get the "status" or whether or not it was successful?
My current app/views/users/update.js.erb
file looks like this:
console.log("update?");
console.log("<%=@user %>");
which prints:
udate?
#<User:0x639a470>
in the console.
Basically, I want to know if it was successful before trying to do things with @user.
Upvotes: 1
Views: 109
Reputation: 34318
Use:
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
Upvotes: 1