0

2 つの変数 (chapterid と txt) を取り、それらを URL のパラメーターとして使用する次の JavaScript があります。「txt」は、ユーザーの選択から派生します。

私の問題: ユーザーの選択にピリオドが含まれていると、routes.rb ファイルに URL の一致の問題が発生するか、ピリオドの後のすべてが無視される可能性があります。

例:

ルート.rb

match "readers/chapannotations/new/:chapterid/:selection/"  => "readers#newchapannotation"

JavaScript

      url = '/readers/chapannotations/new/' + chapterid + '/' + txt + '/';
      console.log(url);
      window.location = url;


txt = 'O Arjuna.'
URL that opens: http://mysite.com/readers/chapannotations/new/5/O%20Arjuna./

これにより、routes.rb に一致する URL がないため、URL が開かれません。これは「。」のせいだと思います。txt の末尾にあります。

txt = 'O アルジュ​​ナ' http://mysite.com/readers/chapannotations/new/5/O%20Arjuna/

この URL は問題なく開きます。ピリオドがないためだと思います。

4

1 に答える 1

0

あなたはあなたの中でこれを試すことができますroutes.rb:

match "readers/chapannotations/new/:chapterid/:selection/"  => "readers#newchapannotation", :selection => /.*/
于 2013-05-07T11:27:06.090 に答える