gpt4 book ai didi

mysql - 无法使用 Ruby on Rails 从 MySql 按 ID 查找数据

转载 作者:行者123 更新时间:2023-11-30 22:08:20 25 4
gpt4 key购买 nike

def show
@item = Item.find(params[:id])
rescue ActiveRecord::RecordNotFound #customer with that id cannot be found
redirect_to action: :index
end

/////////////////////////////////////////////////////////////////////////

def edit
@item = Item.find(params[:id])
rescue ActiveRecord::RecordNotFound #customer with that id cannot be found
redirect_to action: :index
end

现在的问题是找不到我的数据存在于数据库中。当我输入新数据时,它工作正常,但只有当我需要根据用户要求更新或显示该数据时。然后它说找不到记录,但同时新的输入数据可以像我之前告诉你的那样放入数据库。

最佳答案

<h1>Show Item</h1>
<p>
<strong>Mobile: </strong>
<%= @item.mobile %>
</p>

<p>
<strong>Company: </strong>
<%= @item.company %>
</p>

这是 show.html.erb 文件代码。

控制台输出:

开始 GET "/items.%23%3CItem::ActiveRecord_Relation:0xb515b124%3E"for 127.0.0.1 at 2016-12-04 23:43:09 +0500 ActiveRecord::SchemaMigration 加载(0.4 毫秒)SELECT schema_migrations.* FROM schema_migrations由 ItemsController#index 处理为 项目加载 (0.4ms) SELECT items.* FROM items 在布局/应用程序中呈现项目/index.html.erb(13.4 毫秒)在 309 毫秒内完成 200 OK( View :291.7 毫秒 | ActiveRecord:2.0 毫秒)

关于mysql - 无法使用 Ruby on Rails 从 MySql 按 ID 查找数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40931453/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com