-1

Мой вопрос, когда я нахожусь под кемпер шоу страницеРельсы Детский идентификатор, используя родительский идентификатор

Текущий Camper URL:

campers/1 

и я иду, чтобы нажать на, чтобы просмотреть назначение он использует camper_id для destination_id, который неверен, поэтому скажите, если camper_id равен 1, он будет использовать назначение_ид как 1, и на самом деле идентификатор назначения равен 3, поэтому он говорит: не удалось найти назначение с идентификатором 1.

Tabl е Header

<% @appointments.each do |app| %> 

<%= link_to app.camper.camperName, appointment_path(@camper, @appointment) %> 

Campers Контроллер Показать Действие

@appointments = @camper.appointments 

Camper Модель

has_many :appointments, dependent: :destroy 

Назначение Модель

belongs_to :camper 

Мелкие Вложенные Маршруты Файл

resources :customers, shallow: :true do 
    resources :campers do 
    resources :appointments do 
     resources :orders do 
     member do 
      patch :complete 
     end 
     end 
    end 
    end 
end 

Camper контроллер

class CampersController < ApplicationController 
    before_action :set_camper, only: [:show, :edit, :update, :destroy] 
    # before_action :set_customer, only: [:index, :new, :edit, :create, :update] 
    load_and_authorize_resource 

    # GET /campers 
    # GET /campers.json 
    def index 
    @campers = @customer.campers 
    end 

    def list 
    query = params[:q].presence || "" 
    @campers = Camper.search(query, page: params[:page], per_page: 20, order: {created_at: :desc}) 

    end 

    # GET /campers/1 
    # GET /campers/1.js 
    def show 
    @appointments = @camper.appointments 
    respond_to do |format| 
     format.html 
     format.json 
    end 
    end 

    # GET /campers/new 
    def new 
    @customer = Customer.find(params[:customer_id]) 
    @camper = @customer.campers.build 
    end 

    # GET /campers/1/edit 
    def edit 
    end 

    def page_name 
    "Campers" 
    end 


    # POST /campers 
    # POST /campers.json 
    def create 
    @camper = Camper.new(camper_params) 

    respond_to do |format| 
     if @camper.save 
     format.html { redirect_to camper_path(@camper), notice: 'Camper was successfully created.' } 
     format.json { render :show, status: :created, location: @camper } 
     else 
     format.html { render :new } 
     format.json { render json: @camper.errors, status: :unprocessable_entity } 
     end 
    end 
    end 

    # PATCH/PUT /campers/1 
    # PATCH/PUT /campers/1.json 
    def update 
    respond_to do |format| 
     if @camper.update(camper_params) 
     format.html { redirect_to camper_path(@camper), notice: 'Camper was successfully updated.' } 
     format.json { render :show, status: :ok, location: @camper } 
     else 
     format.html { render :edit } 
     format.json { render json: @camper.errors, status: :unprocessable_entity } 
     end 
    end 
    end 

    # DELETE /campers/1 
    # DELETE /campers/1.json 
    def destroy 
    @camper.destroy 
    respond_to do |format| 
     format.html { redirect_to root_path, notice: 'Camper was successfully deleted.' } 
     format.json { head :no_content } 
    end 
    end 

    private 
    # Use callbacks to share common setup or constraints between actions. 
    def set_camper 
     @camper = Camper.find(params[:id]) 
    end 


    # Never trust parameters from the scary internet, only allow the white list through. 
    def camper_params 
     params.require(:camper).permit(:order_id, :customer_id, :year, :manufacturer, :modelName, :camperClass, :vin, :mileage, :notes, :user_id) 
    end 
end 

НАЗНАЧЕНИЯ Controller

class AppointmentsController < ApplicationController 
    before_action :set_appointment, only: [:show, :edit, :update, :destroy] 
    # GET /appointments 
    # GET /appointments.json 
    def index 
    @camper = Camper.find(params[:camper_id]) 
    @appointments = @camper.appointments 
    end 

    # GET /appointments/1 
    # GET /appointments/1.json 
    def show 
    @orders = @appointment.orders 
    end 

    # GET /appointments/newå 
    def new 
    @camper = Camper.find(params[:camper_id]) 
    @appointment = @camper.appointments.build 
    end 

    # GET /appointments/1/edit 
    def edit 
    end 

    # POST /appointments 
    # POST /appointments.json 
    def create 
    @appointment = Appointment.new(appointment_params) 

    respond_to do |format| 
     if @appointment.save 
     format.html { redirect_to appointment_path(@appointment), notice: 'Appointment was successfully created.' } 
     format.json { render :show, status: :created, location: @appointment } 
     else 
     format.html { render :new } 
     format.json { render json: @appointment.errors, status: :unprocessable_entity } 
     end 
    end 
    end 

    # PATCH/PUT /appointments/1 
    # PATCH/PUT /appointments/1.json 
    def update 
    respond_to do |format| 
     if @appointment.update(appointment_params) 
     format.html { redirect_to @appointment, notice: 'Appointment was successfully updated.' } 
     format.json { render :show, status: :ok, location: @appointment } 
     else 
     format.html { render :edit } 
     format.json { render json: @appointment.errors, status: :unprocessable_entity } 
     end 
    end 
    end 

    # DELETE /appointments/1 
    # DELETE /appointments/1.json 
    def destroy 
    @appointment.destroy 
    respond_to do |format| 
     format.html { redirect_to camper_appointments_path(@appointment), notice: 'Appointment was successfully deleted.' } 
     format.json { head :no_content } 
    end 
    end 

    private 
    # Use callbacks to share common setup or constraints between actions. 
    def set_appointment 
     @appointment = Appointment.find(params[:id]) 
    end 

    # Never trust parameters from the scary internet, only allow the white list through. 
    def appointment_params 
     params.require(:appointment).permit(:customer_id, :camper_id, :order_id, :title, :description, :date_in, :date_out) 
    end 
end 

ответ

0

appointment_path принимает только один аргумент назначения. Удалите @camper аргумент:

appointment_path(@appointment) 
+0

У меня есть неглубокие ресурсы, так что 'camper_appointment_path' не будет работать – austinrocks1995

+0

с этим я не получаю' нет соответствующего маршрута {: действие => «шоу»,: контроллер => «назначения»,: идентификатор => nil} отсутствующие требуемые ключи: [: id] ' – austinrocks1995

+0

У меня есть точная настройка для клиентов/туристов, и она работает безупречно, и ive попробовала реплицировать ее кемпер/встречи, и она просто не хочет работать – austinrocks1995