Render nothing; go nowhere

I am building an application that requires a C++ program to access the
Rails web application using POST. Now, I just added user authentication
to the mix and it has made things more interesting.

I’m using basic authentication as shown in the AWDWR and Rails Recipes
books. I can now get my C++ program to submit the user credentials to
the login/login page. All I want the login page to do (in this case) is

  1. Set the session cookie and return it to me (so that I can pass it up
    when I submit the data to the main form)
  2. Indicate a success code - Success/ Failed.

The login action is also used by other parts of the web application
which requires it to redirect to:

  1. Either the action saved in the session
  2. the Administration index page

My C++ Client has a custom user_agent setting so that I know when the
request has come from it. Now, I’m trying to figure out how to return a
specific value to this client only - hence, the need to render nothing
(special) and go to no specific URL. Any ideas? This is what my
login/login action looks like.

def login
session[:user_id] = nil
user = User.authenticate(params[:name], params[:password])
if user
session[:user_id] =
if session[:intended_action].nil? ||
if (@request.env[‘HTTP_USER_AGENT’] == “MyCustomCClient”)
#did it come from my C++ program?
#### <---- I need something here -----> ####
redirect_to(:action => “index”) #deals with direct
access to /login/login
redirect_to :action => session[:intended_action],
:controller => session[:intended_controller]
flash[:notice] = “Invalid user/password combination”


I think I may have figured this out by reading the manual - apologies
for the question.
It seems that I could use:

Renders the clear text “hello world” with status code 200

render :text => “hello world!”


You could also use :

render :nothing => true

That will just send a 200 ok response with no content


Thanks, Ezra! In retrospect, I’d like to render a bit of text so that
my application receives the status directly… but your solution is
perfect (and actually what I had asked for)!


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs