LoginSignup
1
2

More than 5 years have passed since last update.

JavaScriptでGETのパラメータをパースしたい(Rails)

Posted at

正攻法だと、window.location を文字列処理でパース?

でも少し面倒なので、erb でパラメータを埋め込んで渡すという方法を考えた。

hoge.erb
<script>
var params = $.parseJSON('<%= params.to_json().html_safe %>');
</script>

これも気持ち悪いので、もっといい方法が無いかと思ったら、gon という gem があるらしい。
http://qiita.com/mosa_siru/items/e69eee47a183b13cfb62

1
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2