141
122

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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追記

<%# # test.id=1 %>
<%= link_to 'test', test_path(test, company_id: 3) %>

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

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?