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 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿