LoginSignup
0
0

More than 1 year has passed since last update.

Rails 投稿詳細ページ

Last updated at Posted at 2021-08-06

showメソッドを使った投稿詳細ページ

ここでは詳細ページのshowメソッドだけではなく編集と削除機能も追加

officies_controller.rb

  def show
    @office = Office.find_by(id: params[:id])
    render json: { 'office': @office }
  end

  def edit
    @office = Office.find_by(id: params[:id])
  end

  def destroy
    @office = Office.find_by(id: params[:id])
    @office.destroy
    render json: {'office': @office}
  end

ルーティングはresourcesをofficiesにする。

routes.rb

Rails.application.routes.draw do
  namespace :api do
    namespace :v1 do
      mount_devise_token_auth_for 'User', at: 'user_auth', controllers: {
        registrations: 'api/v1/registrations'
        # コントローラーの参照先を設定
    }

      get 'cities', to:'cities#get'

             #省略

      get ':area_id/:prefecture_id/cities', to:'cities#get'
      resources :offices

    end
  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