【发布时间】:2017-07-30 15:34:02
【问题描述】:
我正在尝试在 Ruby on rails 应用程序中为每家餐厅创建一个信息页面。我在Restaurant controller 中创建了一个动作info,并在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) %>
【问题讨论】:
-
这行
<%= link_to 'Info', restaurant_info_path(@restaurant) %>在哪个页面? -
感谢您的回复!在餐厅展示页面中。
标签: ruby-on-rails ruby info