LoginSignup
58
52

More than 5 years have passed since last update.

Railsで自動生成以外のrouteを追加する

Posted at

毎回忘れるのでメモです。

memberとcollectionを利用する

GET /matomes/search で search アクションを呼ぶには以下のように設定する。

# config/routes.rb
resources :matomes do
  collection do
    get :search
  end
end

:id 付きのルーティングの場合はmemberを利用する。

GET /matomes/:id/preview とする場合。

# config/routes.rb
resources :matomes do
  member do
    get :preview
  end
end

参考URL: http://akkunchoi.github.io/rails3-routes.html#member-collection---

58
52
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
58
52