当我访问:
URL/回收/25605
ActiveRecord显示错误RecordNotFound
没有ID无法找到打捞
参数:{"id"=>"25605"}
为什么ActiveRecord搜索"id"当我加入&;typeid &;在参数中?
h2控制器class SalvageController < ApplicationController
def show
@salvage = Salvage.find(params[:typeID])
end
class Salvage < ApplicationRecord
validates :typeID, presence: true
validates :amount, presence: true
end
<<h2>视图/h2><%= @salvage.typeID %>, <%= @salvage.amount %>
resources :salvage
Rails路线Prefix Verb URI Pattern Controller#Action
salvage_new GET /salvage/new(.:format) salvage#new
root GET / application#hello
production_pages_copying GET /production_pages/copying(.:format) production_pages#copying
salvage_index GET /salvage(.:format) salvage#index
POST /salvage(.:format) salvage#create
new_salvage GET /salvage/new(.:format) salvage#new
edit_salvage GET /salvage/:id/edit(.:format) salvage#edit
salvage GET /salvage/:id(.:format) salvage#show
PATCH /salvage/:id(.:format) salvage#update
PUT /salvage/:id(.:format) salvage#update
DELETE /salvage/:id(.:format) salvage#destroy
class SalvageController < ApplicationController
def show
@salvage = Salvage.find(params[:typeID])
end
class Salvage < ApplicationRecord
validates :typeID, presence: true
validates :amount, presence: true
end
<<h2>视图/h2><%= @salvage.typeID %>, <%= @salvage.amount %>
resources :salvage
resources :salvage
Rails路线Prefix Verb URI Pattern Controller#Action
salvage_new GET /salvage/new(.:format) salvage#new
root GET / application#hello
production_pages_copying GET /production_pages/copying(.:format) production_pages#copying
salvage_index GET /salvage(.:format) salvage#index
POST /salvage(.:format) salvage#create
new_salvage GET /salvage/new(.:format) salvage#new
edit_salvage GET /salvage/:id/edit(.:format) salvage#edit
salvage GET /salvage/:id(.:format) salvage#show
PATCH /salvage/:id(.:format) salvage#update
PUT /salvage/:id(.:format) salvage#update
DELETE /salvage/:id(.:format) salvage#destroy
Prefix Verb URI Pattern Controller#Action
salvage_new GET /salvage/new(.:format) salvage#new
root GET / application#hello
production_pages_copying GET /production_pages/copying(.:format) production_pages#copying
salvage_index GET /salvage(.:format) salvage#index
POST /salvage(.:format) salvage#create
new_salvage GET /salvage/new(.:format) salvage#new
edit_salvage GET /salvage/:id/edit(.:format) salvage#edit
salvage GET /salvage/:id(.:format) salvage#show
PATCH /salvage/:id(.:format) salvage#update
PUT /salvage/:id(.:format) salvage#update
DELETE /salvage/:id(.:format) salvage#destroy
我第二次使用我自己的数据在learnenough.com上学习ruby on rails第6版教程
多亏了Deepak Mahakale,我运行了rails路由命令,并注意到在GET路由的末尾添加了:id(format)
。
我搜索了关于将:id(format)
更改为其他内容的问题的堆栈溢出,并遇到:
修改Rails路由中的id参数
因此,我将路由器中的Resources更改为:resources :salvage, param: :typeID
显示视图现在工作,尽管相当慢我将对资源这个话题做更多的研究,以获得更清晰的理解。
我希望这个答案对任何可能遇到同样问题的人有用