我在 Flash Builder 4 中有一个 HTTPService,定义如下:
<s:HTTPService id="getUserDetails" url="http://localhost:3000/users/getDetails" method="GET"/>
它被调用如下:
getUserDetails.send({'user[username]': calleeInput.text});
这是网络监视器的屏幕截图,显示参数正在正确发送(它是“kirsty”):
替代文字 http://img87.imageshack.us/img87/7513/screenshot20100430at548.png
这是它连接到的 Ruby on Rails 方法:
def getDetails
@user = User.find_by_username(:username)
render :xml => @user
end
当我运行它时,我在控制台中得到以下错误输出:
处理 UsersController#list (for 127.0.0.1 at 2010-04-30 17:48:03) [GET] User Load (1.1ms) SELECT * FROM "users" 在 30ms 内完成 (查看: 16, DB: 1) | 200 OK [ http://localhost/users/list]
处理 UsersController#getDetails (for 127.0.0.1 at 2010-04-30 17:48:13) [GET] 参数:{"user"=>{"username"=>"kirsty"}}
用户负载 (0.3ms) SELECT * FROM "users" WHERE ("users"."username" = '--- :username ') LIMIT 1ActionView::MissingTemplate(视图路径app/views中缺少模板users/getDetails.erb):
app/controllers/users_controller.rb:36:in service' /usr/local/lib/ruby/1.8/webrick/httpserver.rb : 65:in start_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:162:in start_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:95:in each' / usr/local/lib/ruby/1.8/webrick/server.rb:92:in start' /usr/local/lib/ruby/1.8/webrick/server.rb:82:in 'start'getDetails'
/usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:inrun'
/usr/local/lib/ruby/1.8/webrick/server.rb:173:instart'
/usr/local/lib/ruby/1.8/webrick/server.rb:162:instart'
/usr/local/lib/ruby/1.8/webrick/server.rb:92:instart'
/usr/local/lib/ruby/1.8/webrick/server.rb:23:in渲染救援/布局 (internal_server_error)
我不确定错误是否是由 getDetails Ruby on Rails 方法中的错误代码引起的?我是 RoR 的新手,我想我记得在某个地方读到过,每种方法都应该有一个视图。我只是使用这种方法将信息获取到 Flex 4 应用程序中,我还需要为其创建视图吗?这是导致错误的原因吗?任何帮助将不胜感激,我已经坚持了几天了!谢谢。
编辑:
根据 Toby Hede 的建议,我将 HTTPService 更改如下,添加 .xml:
<s:HTTPService id="getUserDetails" url="http://localhost:3000/users/getDetails.xml" method="GET"/>
现在我收到以下错误:
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)