views:

45

answers:

1

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

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 1

ActionView::MissingTemplate (Missing template users/getDetails.erb in view path app/views):
app/controllers/users_controller.rb:36: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'

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/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'

Rendering rescues/layout (not_found)
+1  A: 

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.

Toby Hede
How would I make the call to a ".xml"? Sorry, I'm still learning and don't know very much! Thanks for your help.
ben
I meant change the url to have .xml on the end: "http://localhost:3000/users/getDetails.xml"
Toby Hede
Ah haha can't believe I didn't work that out. I made the change, and am getting a different error now. I'll edit it into the original message. Is there a better way for me to post updated code/errors than that? Thanks again!
ben