【发布时间】:2018-01-16 22:14:33
【问题描述】:
我安装了 Rails 5。我无法让我的显示页面呈现。我的 rake 路线有这个
votes_show GET /votes/show(.:format) votes#show
然后在我的 app/controllers/votes_controller.rb 文件中我有
def show
id = params[:id]
# If there is no person selected based on the param, choose one randomly
if !id.present?
@person = Person.order("RANDOM()").limit(1).first
else
@person = Person.find(:id => params[:id])
end
但是当我去http://localhost:3000/votes/1时,我得到一个
No route matches [GET] "/votes/1"
错误。我错过了一些非常明显的东西。这是什么?
【问题讨论】:
-
您的
rake routes应该显示GET /votes/:id(.:format) votes#show。将您的routes.rb文件添加到问题中。 -
你是如何创建演出路线的?
-
@hashrocket,我在 config/routes.rb 文件中添加了“get 'votes/show'”。
-
你使用的是 RESTful 路由吗?
-
这是我的 config/routes.rb 文件中唯一与我的“投票”控制器有关的东西。不确定这是否能回答您的问题。
标签: ruby-on-rails http-status-code-404 ruby-on-rails-5 rails-routing