没有路由匹配“缺少必需的密钥:”

如何解决没有路由匹配错误消息 – >没有路由匹配{:action =>“show”,:controller =>“cost”,:format => nil,:id => nil,:travel_id => nil}缺失必填项:[:id,:travel_id]


routes.rb中:

resources :travels do resources :costs end resources :profiles resources :homes devise_for :users 

Costs_controller:

  before_action :set_travel before_action :set_cost, only: [:show, :edit, :update, :destroy] def index @travel = Travel.find(params[:travel_id]) if current_user.present? @costs = @travel.costs.all else redirect_to '/users/sign_in' end end def new @travel = Travel.find(params[:travel_id]) if current_user.present? @cost = @travel.costs.new else redirect_to '/users/sign_in' end end def create @travel = Travel.find(params[:travel_id]) @cost = @travel.costs.new(costs_params) respond_to do |format| if @cost.save format.html { redirect_to travel_cost_path(@costs), notice: 'Cost was successfully created.' } format.json { render :show, status: :created, location: @cost } else format.html { render :new } format.json { render json: @cost.errors, status: :unprocessable_entity } end end end 

我的模特:

 class Travel < ActiveRecord::Base belongs_to :user has_many :costs end class Cost < ActiveRecord::Base belongs_to :travel end 

我的费用_form:

   

prohibited this cost from being saved:





如果可能请帮助我,我正处于这个问题的时候。 谢谢。

更改

 format.html { redirect_to travel_cost_path(@costs), notice: 'Cost was successfully created.' } 

 format.html { redirect_to travel_cost_path(@travel, @cost), notice: 'Cost was successfully created.' }