0

私の chap_three_controller.rb ファイル:

class ChapThreeController < ApplicationController
   def create
      @marker = Marker.new(params[:m])
      if @marker.save
         res={:success=>true,:content=>"<div><strong>found </strong>#{marker.found}
              </div><div><strong>left </strong>#{marker.left}</div>"}
      else
         res={:success=>false,:content=>"Could not save the marker"}
      end
      render :text=>res.to_json
   end
end

私の routes.rb ファイル

match '/map3', :to => 'chap_three#map'
match '/map3/create', :to => 'chap_three#:action'

コントローラーの create 関数を自分のルートに正しく一致させていますか? 効いてないから..

これは私のjavascriptコードのスニペットです:

request.open('GET', 'create' + getVars, true);
 request.onreadystatechange = function() {
    if (request.readyState == 4) {
 //the request is complete
    var success=false;
    var content='Error contacting web service';
    try {
 //parse the result to JSON (simply by eval-ing it)
      res=eval( "(" + request.responseText + ")" );
      content=res.content;
      success=res.success;
    }catch (e){
       success=false;
     }

私が取得し続けるエラーは、「Web サービスへの接続エラー」です。これは、私の request.responseText が機能しておらず、コントローラーの create メソッドが何もしていないことを意味します....どんな助けも素晴らしいでしょう

4

1 に答える 1

0

マッチを次のようにします。

match '/map3/create' => 'chap_three#create'

#コントローラー名とアクション名をそれぞれ区切ります。:toは不要であり、rootルートを定義するときにのみ使用されます。Rails Routing Guideを読むことをお勧めします

于 2013-02-08T05:08:10.230 に答える