xxxbt 2011-10-14 12:10
浏览 286
已采纳

帮忙解释一下下面这段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]

尽量说详细点,谢谢!

  • 写回答

3条回答 默认 最新

  • horace_lee 2011-10-15 05:50
    关注

    要说解释这段代码,有这些东西可以说
    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]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器