Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • using head to create header response

    • 0
    • 1
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 226
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: