2011-01-07 8 views
0

私はボタンをクリックしているときにjavascript "showpopupfunc()"を呼び出すと、RORのmenthod "addmcf"を実行する必要があります。ruby​​ on railのJavaスクリプトからRORメソッドを呼び出す方法は?

<button class="button" id="buttonUpload" onclick="showpopupfunc()" >&nbsp;</button> 

<script> 
     function ajaxFileUpload() 
     { 
      $j.ajaxFileUpload 
      (
       { 
        url:'/ptcgeodatabase', 
        secureuri:false, 
        fileElementId:'fileToUpload', 
        dataType: 'json', 
        success: function (data, status) 
        { 
         if(typeof(data.error) != 'undefined') 
         { 
          if(data.error != '') 
          { 
           alert(data.error); 
          }else 
          { 
           alert(data.msg); 
          } 
         } 
        }, 
        error: function (data, status, e) 
        { 
         alert(e); 
        } 
       } 
      ) 
      return false; 
     } 

     function showpopupfunc() 
     { 
      **window.location="http://127.0.0.1:3006/ptcgeodatabase#addmcf"** 
      showPopWin2('processing', 200, 70, null); 
      setConfirmUnload(false); 


      ajaxFileUpload(); 
     } 
     function addFiles(selectObject, seltext, selvalue) 
     { 
      var optionObject = new Option(seltext,selvalue); 
      var optionRank = document.getElementById("mcffiles").options.length; 
      if(optionRank <= 9) 
      { 
       document.getElementById("mcffiles").options[optionRank]= optionObject; 
      } 
      else 
       alert('Only 9 files can select') 
     } 
     </script> 

コントローラー:

def addmcf 
# i am doing some operation 
@path=RAILS_ROOT.to_s+"/tmp/upload" 
     @mcfdir=Dir[@path+"/*"] 
     @x='' 
     for i in 0..(@mcfdir.length-1) 
     @[email protected][email protected][i].to_s+'|' 
     end 
end 

答えて

2

さてあなたは、対応するコントローラのアクションでコードを実行します(例えば、AJAXリクエスト)HTTPリクエストでURLを打つことができます。デフォルトで http://127.0.0.1:3006/ptcgeodatabase/addmcf

ルーティングする

addcmf PTCGeoDatabaseController位を実行すべきである。例えば

、(大文字が異なる場合があり、その結果が定義されている経路に依存する。)

関連する問題