Is there a difference between
def create
@user = User.new(params[:user])
if @user.save
redirect_to root_url, :notice => "Signed up!"
else
render :new
end
end
and
def create
@user = User.new(params[:user])
respond_to do |format|
if @user.save
format.html { redirect_to(:users, :notice => 'Registration successfull. Check your email for activation instructions.') }
format.xml { render :xml => @user, :status => :created, :location => @user }
else
format.html { render :action => "new" }
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
end
end
end
Ignore the error and notice issues, my main question is the difference between using xml format and not using it, they seem to do the exact thing.
Using
respond_towith different format than html give you the ability to have the response in the specified format (useful for web-service).In that case (User creation) I don’t think it is really useful, but it’s all up to you!
Not using
respond_tolike your first exemple will simply render html.More infos about
respond_tohere:http://apidock.com/rails/ActionController/MimeResponds/InstanceMethods/respond_to