views:

55

answers:

1

EDIT:

Got too confusing with so many different edits, so this is where I'm currently at.

I have a HTTPService in my Flex 4 app defined as follows:

<s:HTTPService id="getUserDetails" url="http://localhost:3000/users/getDetails" method="GET"/>

I call this service like this (note: I've checked the network monitor in Flash Builder 4 and the userNameLookup variable is sent correctly):

var userNameLookup:String;
userNameLookup = calleeInput.text;
getUserDetails.send(userNameLookup);

And finally, this is the Ruby on Rails method:

def getDetails
  @user = User.find_by_username(:userNameLookup)
  render :xml => @user
end

This is the error message in the log:

Processing UsersController#getDetails (for 127.0.0.1 at 2010-04-27 19:24:23) [GET] User Load (0.2ms) SELECT * FROM "users" WHERE ("users"."username" = '--- :userNameLookup ') LIMIT 1

ActionView::MissingTemplate (Missing template users/getDetails.erb in view path app/views):
app/controllers/users_controller.rb:33:in getDetails'
app/controllers/users_controller.rb:32:in
getDetails'
/usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in service'
/usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in
run'
/usr/local/lib/ruby/1.8/webrick/server.rb:173:in start_thread'
/usr/local/lib/ruby/1.8/webrick/server.rb:162:in
start'
/usr/local/lib/ruby/1.8/webrick/server.rb:162:in start_thread'
/usr/local/lib/ruby/1.8/webrick/server.rb:95:in
start'
/usr/local/lib/ruby/1.8/webrick/server.rb:92:in each'
/usr/local/lib/ruby/1.8/webrick/server.rb:92:in
start'
/usr/local/lib/ruby/1.8/webrick/server.rb:23:in start'
/usr/local/lib/ruby/1.8/webrick/server.rb:82:in
start'

So it appears that the userNameLookup parameter isn't being referred to correctly? Just a thought, but does it matter that I've set the HTTPService to GET even though it is posting something?

+2  A: 

The controller action methods should be implemented without parameters. The parameters can be inferred from the request parameters.

Try this:

def getDetails
  @user = User.first(:conditions => {:username => params[:lookupUsername]})
  respond_to do |format|
    format.xml { render :xml => @user }
  end
end

In the code above I have used lookupUsername as the query parameter. Change that to the actual name sent by your flex client.

Edit 1

You need explicit xml format handler to return the result as XML. Apart from this, it looks like lookupUsername parameter is empty in your invocations. Is it possible that the query parameter is named something else? You can get the name of the query parameter by looking at the log file. Your log file should show an entry like this:

Processing xxxxController#getDetails (for 127.xxx at 2010-04-15 10:27:21) [GET]
  Parameters: {"action"=>"getDetails", "controller"=>"xxxx", 
              "lookupUsername" => "bob"}
KandadaBoggu
Hey, thanks for your answer! I tried doing it this way, but I'm still getting the error (which I've pasted into the original question above).
ben
Updated the answer take a look.
KandadaBoggu
I've updated as per your instruction, and I'm no longer getting the ArgumentError (wrong number of arguments (0 for 1)) error. But I am getting a new error. I'll post my updated code and the console error above. Thanks so much for your help.
ben
Updated the answer, take a look.
KandadaBoggu
Updated the question to remove all the old stuff. As I mention up there, you're right, the query parameter isn't being referred to correctly? I've posted the log up there. I'll add your XML suggestion in a bit! I really appreciate all your help, thanks a million.
ben