Noob filter: How do I refer to a string that is passed to my Ruby on Rails method from Flex as a HTTPService?
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);
开发者_StackOverflowAnd 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:ingetDetails' app/controllers/users_controller.rb:32:in
getDetails' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:inservice' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in
run' /usr/local/lib/ruby/1.8/webrick/server.rb:173:instart_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:162:in
start' /usr/local/lib/ruby/1.8/webrick/server.rb:162:instart_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:95:in
start' /usr/local/lib/ruby/1.8/webrick/server.rb:92:ineach' /usr/local/lib/ruby/1.8/webrick/server.rb:92:in
start' /usr/local/lib/ruby/1.8/webrick/server.rb:23:instart' /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?
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"}
精彩评论