Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8332209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:39:26+00:00 2026-06-09T02:39:26+00:00

The code that i am trying to shorten in one line : if !request.xhr?

  • 0

The code that i am trying to shorten in one line:

            if !request.xhr?
                    render_404
                    return
            end

from this function

def request_invite
    render_404 unless request.xhr?

        @invitation = Invite.new(params[:invite])

        if @invitation.save
            @return = { :error => false, :response => "OK" }
        else
            @return = { :error => true, :response => @invitation.errors.full_messages.join("<br />") } 
        end

        render :json => ActiveSupport::JSON.encode( @return )

end

i tried

            render_404 return unless request.xhr?

but i get:

invites_controller.rb:4: void value expressio render_404 return unless request.xhr?

Should i stick with the above code that works or is there a better way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T02:39:28+00:00Added an answer on June 9, 2026 at 2:39 am

    Why do you need the return? The function body does not contains anything else. If it does, please note it.

    def request_invite
       render_404 unless request.xhr?
    end
    

    The main problem is that you can’t write the two command in one line without separation, it tries to evaluate it, but it is syntactically incorrect.

    UPDATE:

    def request_invite
        unless request.xhr? then render_404; return; end
    
        @invitation = Invite.new(params[:invite])
    
        if @invitation.save
            @return = { :error => false, :response => "OK" }
        else
            @return = { :error => true, :response => @invitation.errors.full_messages.join("<br />") } 
        end
    
        render :json => ActiveSupport::JSON.encode( @return )
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just trying to shorten a line of code that assigns HTML::Element->as_trimmed_text from an
I have the following code that i am trying to change from a regular
There is some code that I'm trying to convert from IList to IEnumerable :
Is this possible, or am I just trying to way overly shorten my code?
In C#, I am trying to shorten some of my return code. What I
When trying code that looks like this, mainly for testing NSInvocationOperation *operation = [NSInvocationOperation
here i have this code that i'm trying where openingHoursView.ohLocation has two values value1
Below is a snippet of code that is trying to post to a PHP
Here is my Code that I'm trying to run on Mac OS X: import
I have the following code that I am trying to extract the systems proxy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.