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 6541233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:04:47+00:00 2026-05-25T11:04:47+00:00

Is there a way to use a flat .rb file to accept POST requests,

  • 0

Is there a way to use a flat .rb file to accept POST requests, or do I need to use a framework like Rails or Sinatra to accept the request?

I’m thinking along the lines of how I can use a flat .php file to accept POST requests, and use the $_REQUEST[] variable to access passed data.

Even more specifically, I’m trying to learn a bit of Ruby by porting over one of my Twilio apps from PHP. The app accepts SMS, processes the message sent, and sends a reply based on the body of the message received.

While using PHP, I can set the SMS Request URL in the Twilio site to my PHP file. The PHP file uses the $_REQUEST[] array to use the message that was received. (It seems like the Ruby equivalent to this is params[].)

Here’s a quick example of the PHP version of what I’m talking about:

<?php
require "twilio.php";           // Twilio Library
$ApiVersion     = "2010-04-01"; // Twilio API Version
$AccountSid     = "SID";        // Twilio SID
$AuthToken      = "TOKEN";      // Twilio Token

// Instantiate a new Twilio Rest Client
$client = new TwilioRestClient($AccountSid, $AuthToken);

// Get message body & who it's from, for the SMS that was just received
$SMSbody = mysql_real_escape_string($_REQUEST['Body']);

if ($SMScode == "codeword"){
        $SMSresponse = "You know the code.";
}
else{
        $SMSresponse = "You do not know the code.";
}

// Twilio response to the sender
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
    <Sms><?php echo $SMSresponse;?></Sms>
</Response>

Here’s my attempt at a Ruby equivalent, which is probably offensively bad:

require "rubygems"
require "twilio-ruby"

@account_sid = "SID"
@auth_token = "TOKEN"
smsbody = params['body']

@client = Twilio::REST::Client.new(@account_sid, @auth_token)
@account = @client.accounts.get(@account_sid)

if smsbody == "codeword"
    smsreply = "You know the code"
else
    smsreply = "You do not know the code"

response = Twilio::TwiML::Response.new do |r|
    r.Sms smsreply
end

# print the result
puts response.text

This results in the Twilio debugging dashboard stating that the reply was more than 160 characters. This is because the reply is the full Ruby code, not the result of having ran the Ruby code. This makes me think that the POST request isn’t being accepted correctly…

  • 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-05-25T11:04:48+00:00Added an answer on May 25, 2026 at 11:04 am

    Based on the existing answers, and all the other research I’ve done, it doesn’t seem like there’s one single Answer to this question. It’s another one of those TIMTOWTDI situations. Here’s a summary of what I’ve learned so far, though…

    The ability to drop PHP files into Apache & have it work properly is made possible by mod_php, which is enabled by default (making it seem seamless).

    The params[] array is actually a Rails-specific helper. To get the same functionality, one would have to parse the request body (STDIN) on their own (perhaps with the CGI.parse function provided by the CGI module).

    There seem to be a few options in my case:

    • Use Passenger to let Apache run a Rack-based Ruby app (like Camping,
      Sinatra, or Rack)
    • Use a pure Ruby web server like Unicorn or Thin
    • Call the Ruby script via PHP’s passthru function

    The way forward for someone who wants to stick to strictly-Ruby (not using the PHP passthru function) without straying too far away from the familiarity of Apache might be to use Passenger with either Camping or Sinatra.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to use inheritance in database (Specifically in SQL Server 2005)?
Is there a way to use JQuery to cloak or encrypt email addresses on
Is there any way to use a constant as a hash key? For example:
Is there a way to use constants in JavaScript ? If not, what's the
Is there a way to use form fields that does not correspond to database
Is there any way to use C# to build a container application where each
Is there a way to use .NET reflection to capture the values of all
Is there a way to use Enum values inside a JSP without using scriptlets.
Is there a way to use THE LOOP in Wordpress to load pages instead
Is there a way to use a foreach loop to iterate through a collection

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.