LoginSignup
0
0

More than 1 year has passed since last update.

新method追加

Last updated at Posted at 2021-05-13

member
「member」とは、「resources以外のメソッドを追加したい」且つ「id情報を伴うURIを生成したい」時に使用します。使い方は以下の通りです。

memberの使い方①

member do 
  HTTPメソッド  ‘アクション名’
end

ただ、追加したいアクションが1つだけの時は以下のように記述出来ます。

memberの使い方②

  HTTPメソッド  ‘アクション名’ , on:  :member

今回は「orderメソッド(購入機能のメソッド)」に対してmemberを使います。
それではルーティングを設定しましょう。

ルーティングを設定しましょう
ルーティングを以下のように設定してください。

config/routes.rb
Rails.application.routes.draw do
  devise_for :users
  root to: "items#index"
  resources :items do
   resources :purchases, only: [:index, :create]
  end
end

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