While sending an ajax request in rails sometimes we dont need to render any data back to the page . Only status 200 is sufficient to show changes in the view page then we use render :nothing option but there is an alternative to it is head method. This method generate only header response without any content in it. This method takes various header names and their values as its optional arguments.
Example:
def resend_confirmation_email
@user = User.find(params[:id])
authorize @user, :update?
flash[:success] = "Resend Confirmation Email!"
head :ok, :content_type => 'text/html' # or head :200, :content_type => 'text/html'
end
We can use head to send header for bad request also.
head :bad_request
0 Comment(s)