如何让我的 "show" 页面呈现?
How do I get my "show" page to render?
我安装了 Rails 5。我无法呈现我的显示页面。我的佣金路线有这个
votes_show GET /votes/show(.:format) 投票#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"
错误。我错过了一些非常明显的东西。这是什么?
votes_show GET /votes/show(.:format) votes#show
这一行告诉 rails "when you see a route that is /votes/show
then go to the VotesController#show
method."
当您随后输入 /votes/1
时,rails 正在对照路线检查它,但没有找到看起来像那样的路线...它专门寻找 而已 对于 /votes/show
如评论中所述,您必须添加一行:
get '/votes/:id(.:format)', to: 'votes#show'
或者更好的是,使用像
这样的足智多谋的路线
resources :votes
我安装了 Rails 5。我无法呈现我的显示页面。我的佣金路线有这个
votes_show GET /votes/show(.:format) 投票#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"
错误。我错过了一些非常明显的东西。这是什么?
votes_show GET /votes/show(.:format) votes#show
这一行告诉 rails "when you see a route that is /votes/show
then go to the VotesController#show
method."
当您随后输入 /votes/1
时,rails 正在对照路线检查它,但没有找到看起来像那样的路线...它专门寻找 而已 对于 /votes/show
如评论中所述,您必须添加一行:
get '/votes/:id(.:format)', to: 'votes#show'
或者更好的是,使用像
这样的足智多谋的路线resources :votes