请帮我解决这个关于使用 HTTPService 连接 Flex4 和 Flex4 的错误。红宝石 on Rails

发布于 2024-08-30 16:31:02 字数 3326 浏览 4 评论 0原文

我在 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 (用于 127.0.0.1 at 2010-04-30 17:48:03) [GET] 用户负载 (1.1ms) 选择 * FROM“用户”在 30 毫秒内完成(查看: 16、数据库:1) | 200 好 [http://localhost/users/list]

处理 UsersController#getDetails (对于 127.0.0.1,2010-04-30 17:48:13) [获取]参数: {“用户”=>{“用户名”=>“柯斯蒂”}}
用户负载 (0.3ms) SELECT * FROM “用户”WHERE(“用户”。“用户名”= '--- :用户名 ') LIMIT 1

ActionView::MissingTemplate(缺少 视图中的模板 users/getDetails.erb 路径应用程序/视图):
应用程序/控制器/users_controller.rb:36:in 获取详细信息
/usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in
服务'
/usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in 运行'
/usr/local/lib/ruby/1.8/webrick/server.rb:173:in
start_thread'
/usr/local/lib/ruby/1.8/webrick/server.rb:162:in 开始'
/usr/local/lib/ruby/1.8/webrick/server.rb:162:in
start_thread'
/usr/local/lib/ruby/1.8/webrick/server.rb:95:in 开始'
/usr/local/lib/ruby/1.8/webrick/server.rb:92:in
每个'
/usr/local/lib/ruby/1.8/webrick/server.rb:92:in 开始'
/usr/local/lib/ruby/1.8/webrick/server.rb:23:in
开始'
/usr/local/lib/ruby/1.8/webrick/server.rb:82:in `开始'

渲染救援/布局 (内部服务器错误)

我不确定该错误是否是由 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)

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 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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘿哥们儿 2024-09-06 16:31:02

问题是 Rails 正在相应的视图文件夹中查找 getDetails.erb.html 文件。您需要向末尾带有“.xml”的 url 发出请求,以告诉服务器您需要 XML 响应。否则它默认为 HTML,从而导致此错误。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文