2016-12-02 32 views
1
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 

现在问题在于它没有找到我的数据存在于数据库中。当我把新的数据,然后它工作正常,但只有当我需要更新或显示用户需求的数据。然后它说没有找到记录,但同时新的输入数据可以放入数据库中,就像我之前告诉过你的那样。使用Ruby on Rails无法通过MySql中的ID查找数据

+0

你尝试过执行轨控制台上的查询和看到的结果显示 – Bijendra

+0

给像@item = Item.find一试(PARAMS [:ID] .to_i) – Ranzit

+0

我更新ucing轨控制台的值,但我没能这样做使用代码....我也试过这@item = Item.find(params [:id] .to_i)但没有任何改变....我卡在这里请帮助???????? – Thinkerzz

回答

0
<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” 为127.0.0.1,在2016年12月4日23时43分09秒0500 的ActiveRecord :: SchemaMigration负荷(0.4ms)SELECT schema_migrations。* FROM schema_migrations 处理由上述ItemsController#索引作为 项目负载(0.4ms)SELECT items。* FROM items 渲染项/布局内index.html.erb /应用(13.4ms) 在309ms完成200 OK(查看:291.7ms | ActiveRecord:2.0ms)