帮忙解释一下下面这段ruby代码!

[code="java"]
<% form_remote_tag(:url => load_wsdl_soap_services_url,
:update => { :success => 'soap_service_after_wsdl_load' },
:success => "new Effect.Highlight('soap_service_form', { duration: 1.5 });",
:failure => "alert('Sorry, an error has occurred.');",
:loading => "Element.show('spinner')",
:complete => "Element.hide('spinner')") do %>

<div>
    <p style=" margin-top: 0;">
        <%= text_field_tag "wsdl_url", params[:wsdl_url], :style => "width: 550px" -%>
        <%= submit_tag "Preview" -%>
        <%= image_tag icon_filename_for(:spinner), :id => "spinner", :style => "display: none; vertical-align: middle;" -%>
    </p>
</div>

<% end -%>
[/code]

尽量说详细点,谢谢!

要说解释这段代码,有这些东西可以说
1. 这个代码比较老,最多是2.*的代码。因为form_remote_tag这个表单标签3.0后就deprecated了。或者,你是想问,form_remote_tag的参数,希望有人详尽解释?其实,那几个参数都很简单,看API都很清楚,只是3.0后没有了,所以,我就贴个在后面了。
两个随便说说
[code="ruby"] :url => load_wsdl_soap_services_url,

[/code]是个convention,(因为,你没说清到底问啥,那我只好瞎猜,看见啥说啥了)去掉_url,去router.rb查看路由怎么设置,可以找到对应的ajax调用的方法。
[code="ruby"]
:update => { :success => 'soap_service_after_wsdl_load' }, [/code]
这个本来是一对update是说更新,success是ajax成功更新那个dom后面的[quote]soap_service_after_wsdl_load[/quote]是dom的id,通常还应该有
[code="ruby"] :failure=>'dom_id'[/code]是对应,ajax调用失败更新dom 的id

后面的参数看最后,
哦,如果,可以的话,最好别仔细研究那些参数用法,因为那都是prototype的用法,rails3之后就Jquery了,研究了也不会用到了。

  1. 解释代码的话,还有个可以说吧

[code="ruby"]image_tag icon_filename_for(:spinner)[/code]
image_tag有些关于处理cache的作用,转html后会看到MD5,如果MD5不一致,即使浏览器缓存了也会更新
icon_filename_for是个helper到helper下查对应的action名helper

  1. form_remote_tag deprecated是因为,会在html页面生成很多内嵌的javascript和内容,行为分离,convention违背。应该改成form_tag :remote => true。

  2. 页面内的那些css style很扎眼,就这么一提哈

别的没啦,这些吧。

[quote]

:loading: Called when the remote document is being loaded with data by the browser.
:loaded: Called when the browser has finished loading the remote document.
:interactive: Called when the user can interact with the remote document, even though it has not finished loading.
:success: Called when the XMLHttpRequest is completed, and the HTTP status code is in the 2XX range.
:failure: Called when the XMLHttpRequest is completed, and the HTTP status code is not in the 2XX range.
:complete: Called when the XMLHttpRequest is complete (fires after success/failure if they are present).
[/quote]

就是吧一个地址页面的数据传过来,

通过soap方式调用webservice:解析wsdl文件并调用webservice暴露出的接口,
success 和 failure 是返回给你调用成功或失败后的处理。