隨筆-167  評論-65  文章-0  trackbacks-0

          上一遍我介紹了observe_field,我們知道這些方法都是rails封裝好的ajax實現,例如還有下面的這些方法,如果想了解更多,請查閱api PrototypeHelper

          build_callbacks
          build_observer
          button_to_remote
          evaluate_remote_response
          form_remote_for
          form_remote_tag
          link_to_remote
          method_option_to_s
          observe_field
          observe_form
          options_for_ajax
          periodically_call_remote
          remote_form_for
          remote_function
          submit_to_remote
          update_page
          update_page_tag

          這次用form_remote_tag 主要是為了驗證用戶登陸的,為了改善用戶的人性化使用,所以能用ajax實現的最好用ajax實現

          實現效果:

          image

          實現過程:

          rhtml:

          <span id="loginerror" class="error"></span>



          <%= form_remote_tag(:url => { :action => :login }) %>

          ……………………….

          <%= form_tag %>


          controller:

          if 驗證成功

            render :update do |page|
              page.redirect_to :controller=>'myorganizer',:action=>'index'
            end
          else 
            render :update do |page|
              page.replace_html 'loginerror', '用戶名或者密碼錯誤'
            end

          注意:

          1,顯示信息的id最好在form的上面,不要在form的里面,不然可能會出錯

          2,使用這種 render :update的方式,不要使用,form_remote_tag 的:update選項的方式(使用這種方式,錯誤可以提示,但是正確了不可以跳轉,因為你更新的是那個指定的id),不然的話會出現下面的錯誤:rjs錯誤

          ajax2

          ref:

          http://www.javaeye.com/topic/34655

          http://railsforum.com/viewtopic.php?id=8510

          http://jmvidal.cse.sc.edu/talks/rubyonrails/form_remote_tag.html



          write by feng
          posted on 2009-04-29 18:21 fl1429 閱讀(2374) 評論(2)  編輯  收藏 所屬分類: Rails

          評論:
          # re: Rails form_remote_tag使用 2009-09-22 13:04 | 金仁貴
          你這個我運行不了,它會跳到一個下載文件,下載文件的內容是要執行的那段js代碼

            回復  更多評論
            
          # re: Rails form_remote_tag使用 2009-09-22 18:11 | fl1429
          @金仁貴
          javascripts :defaults 加入了嗎?。。。還有用了 prototype 就不要加載 jquery 了,不然會沖突的!  回復  更多評論
            
          已訪問數:
          free counters
          主站蜘蛛池模板: 北海市| 荔波县| 图们市| 柳林县| 板桥市| 青田县| 吉首市| 巴楚县| 唐河县| 惠东县| 北流市| 汤阴县| 祁东县| 石楼县| 广西| 防城港市| 阳春市| 阜新市| 安国市| 延川县| 兴业县| 阳城县| 盐边县| 通州市| 聂荣县| 广丰县| 额敏县| 崇仁县| 铜梁县| 吴忠市| 故城县| 巢湖市| 资中县| 城口县| 色达县| 比如县| 大邑县| 广丰县| 平泉县| 张家口市| 苏尼特左旗|