我正在尝试在 Ruby on rails 应用程序中为每家餐厅创建一个信息页面。我创建了一个动作info
我在中Restaurant controller
并在routes.rb
. 但它给出了一个错误
“ActiveRecord::RecordNotFound in RestaurantsController#info”找不到具有 'id'=.. 的餐厅
我的代码有什么问题?
这是我的餐厅控制器:
class RestaurantsController < ApplicationController
before_action :set_restaurant, only: [:show, :edit, :update, :destroy, :info]
def info
end
private
def set_restaurant
@restaurant = Restaurant.find(params[:id])
end
end
这是我的路线.rb:
Rails.application.routes.draw do
resources :restaurants do
get '/info', to: 'restaurants#info'
end
end
这是餐厅信息页面的链接:
<%= link_to 'Info', restaurant_info_path(@restaurant) %>