Why didn't running off the Rails website?



  • Hello, please tell me how to fix the mistake. When he leaves the site, he throws a message - Couldn't find Doctor with 'id'=sign_out and points to.

    @doctor = Doctor.find(params[:id])
    

    Controller

    class DoctorsController < ApplicationController
      before_action :set_doctor, only: [:show, :edit, :update, :destroy]
      def index
        @doctor = Doctor.all
      end
    

    def show
    @length = User.where(doctor_id: params[:id]).size
    end

    private

    def set_doctor
    @doctor = Doctor.find(params[:id])
    end
    end

    I used to get off the website, but now this opportunity is gone. Used by Hem Devise

    UPDATE
    routes.rb

      Rails.application.routes.draw do
    get 'contact/index'

    resources :news
    resources :prices
    get 'healthy/index'
    get 'about/index'

    resources :users
    resources :doctors

    devise_for :doctors, :controllers => { registrations: 'registrations' }
    root 'users#main'

    end

    Reference to withdrawal from session

    <%= link_to 'Вийти', destroy_doctor_session_path %>

    введите сюда описание изображения



  • Take your route. GET /doctors/sign_out And look at the top down list, which rule is the first one.

    And it matches. GET /doctors/:idcollected from resources :doctors♪ Why not? GET /doctors/sign_out (laughs) devise_forif he's right Better.? A No matter what, he's the first fit.♪ It's used.

    The solution is simple. devise_for above resources :doctorsthereby changing the order of these routes on the list so that the first matches. GET /doctors/sign_out


    Alternative, elevated complexity: without changing order, set to parameter :id in the route, the requirement is only numerical, similar to http://guides.rubyonrails.org/routing.html#segment-constraints :

    get 'photos/:id', to: 'photos#show', constraints: { id: /[A-Z]\d{5}/ }
    

    It's the only way out when the routes are very close. It's not your case, in your case, it's enough to change order. But it's only the first reception to deal with such problems, in general, not enough.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2