Please help me work out this error, regarding the use of a HTTPService to connect Flex4 & Ruby on Rails
I have a HTTPService in Flash Builder 4, that is defined as follows:
<s:HTTPService id="getUserDetails" url="http://localhost:3000/users/getDetails" method="GET"/>
It gets called as follows:
getUserDetails.send({'user[username]': calleeInput.text});
Here is a screenshot of the network monitor, showing that the parameter is being sent correctly (it is 'kirsty'):
alt text http://img87.imageshack.us/img87/7513/screenshot20100430at548.png
Here is the Ruby on Rails method that it's connected to:
def getDetails
@user = User.find_by_username(:username)
render :xml => @user
end
When I run it, I get the following error output in the console:
Processing UsersController#list (for 127.0.0.1 at 2010-04-30 17:48:03) [GET] User Load (1.1ms) SELECT * FROM "users" Completed in 30ms (View: 16, DB: 1) | 200 OK [http://localhost/users/list]
Processing UsersController#getDetails (for 127.0.0.1 at 2010-04-30 17:48:13) [GET] Parameters: {"user"=>{"username"=>"kirsty"}}
User Load (0.3ms) SELECT * FROM "users" WHERE ("users"."username" = '--- :username ') LIMIT 1ActionView::MissingTemplate (Missing template users/getDetails.erb in view path app/views):
app/controllers/users_controller.rb:36:ingetDetails' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in
service' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:inrun' /usr/local/lib/ruby/1.8/webrick/server.rb:173:in
start_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:162:instart' /usr/local/lib/ruby/1.8/webrick/server.rb:162:in
start_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:95:instart' /usr/local/lib/ruby/1.8/webrick/server.rb:92:in
each' /usr/local/lib/ruby/1.8/webrick/server.rb:92:instart' /usr/local/lib/ruby/1.8/webrick/server.rb:23:in
start' /usr/local/lib/ruby/1.8/webrick/server.rb:82:in `start'Rendering rescues/layout (internal_server_error)
I'm not sure if the error is being caused by bad code in the getDetails Ruby on Rails method? I'm new to RoR, and I think I remember reading somewhere that every method should have a view. I'm just using this method to get info into the Flex 4 app, do I still need to make a view for it? Is that what's causing the error? Any help would be GREATLY appreciated, I've been stuck on this for a few days now! Thanks.
EDIT:
As per Toby Hede's suggestion, I changed the HTTPService as follows, adding the .xml:
<s:HTTPService id="getUserDetails" url="http://localhost:3000/users/getDetails.xml" method="GET"/>
Now I am getting the following error:
Processing ApplicationController#index (for 127.0.0.1 at 2010-04-30 23:32:29) [GET]
Parameters: {"user"=>{"username"=>"kirsty"}}
ActionController::RoutingError (No route matches "/users/getDetails.xml" with {:method=>:get}):
/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/ser开发者_开发百科ver.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'
Rendering rescues/layout (not_found)
The problem is that Rails is looking for a getDetails.erb.html file in the corresponding view folder. You need to make a request to the url with a ".xml" on the end to tell the server that you want an XML response. Otherwise it defaults to HTML, resulting in this error.
精彩评论