LoginSignup
141
123

More than 5 years have passed since last update.

rails link_toで任意のリクエストパラメータを渡す

Last updated at Posted at 2014-04-24

他により良い方法があるかも知れないけど、次のようにすると渡せる.

tests_controllerのindexにrequestパラメータcompany_id(この場合は3)を付与する例

<%= link_to 'test', controller: "tests", action: "index", company_id: 3>

もっとシンプルに渡せる方法があれば教えて頂きたいです。。。


2014/4/30追記
erb
<%# # test.id=1 %>
<%= link_to 'test', test_path(test, company_id: 3) %>

上記のように記述すると、
http://~~~~/tests/1?company_id=3
が出来上がる。

141
123
1

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
141
123