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

          上一遍我介紹了observe_field,我們知道這些方法都是rails封裝好的ajax實現(xiàn),例如還有下面的這些方法,如果想了解更多,請查閱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實現(xiàn)的最好用ajax實現(xiàn)

          實現(xiàn)效果:

          image

          實現(xiàn)過程:

          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),不然的話會出現(xiàn)下面的錯誤: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 閱讀(2372) 評論(2)  編輯  收藏 所屬分類: Rails

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

            回復  更多評論
            
          # re: Rails form_remote_tag使用 2009-09-22 18:11 | fl1429
          @金仁貴
          javascripts :defaults 加入了嗎?。。。還有用了 prototype 就不要加載 jquery 了,不然會沖突的!  回復  更多評論
            
          已訪問數(shù):
          free counters
          主站蜘蛛池模板: 大渡口区| 右玉县| 临海市| 板桥市| 涞水县| 福清市| 洛隆县| 南川市| 高碑店市| 饶平县| 定陶县| 辽宁省| 泰兴市| 宁都县| 海南省| 邛崃市| 宣化县| 永济市| 池州市| 梅州市| 溆浦县| 武城县| 惠安县| 石台县| 特克斯县| 广元市| 平邑县| 板桥市| 铜陵市| 界首市| 朝阳区| 体育| 醴陵市| 东海县| 都江堰市| 兰坪| 连平县| 白河县| 赣榆县| 海丰县| 澄江县|