8
8

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 で `controller` にパラメータの渡し方

Posted at

バージョン

  • Rails 4.0.0 rc1

内容

event.html.slim
= link_to "参加", join_group_event_path(@group, @event, join_type: Event::JOIN)
event_controller.rb
def join
  @event.event_users.create user: current_user, join_type: params[:join_type]

  redirect_to group_event_path(@group, @event)
end
  • controllerparams[:join_type]で取得できる

ポイント

  • link_toのパラメータではなく、命名ルートのパラメータにしないと行けない

懸念点

  • join_type は生のままクライアントまで分かられていることは、大丈夫かな?
  • そもそも joinGET ではなく POST では?
8
8
0

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
8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?