Rails - 设置自己的主键并删除rails-set id会导致问题
对于我的 Rails 应用程序,我使用脚手架方法来创建表和视图,并希望通过在模型中设置自己的主键(使用“set_primary_key”)来修改员工模型。我想使用“personel_number”列作为我的主键。
但当然它的效果并不那么好。我已经删除了rails-set id。如果我创建一个新员工并想要提交它,rails 路由错误,它仍然路由到 [...]/employees/1 而不是 [...]/employees/5000 (这是 personel_number)。
首先我想,这个问题可以通过将 @employee = Employee.find(params[:id])
更改为 @employee = Employee.find(params[:personel_number])< /code> 但这不起作用:
ActiveRecord::RecordNotFound in EmployeesController#show
Couldn't find Employee without an ID
我该如何解决这个问题?
For my rails app, I used the scaffolding method to create the tables and the views and wanted to modify the employees model with setting an own primary key (with 'set_primary_key') in my model. I wanted to use the column "personel_number" as my primary key.
But of course it's not working that well. I already deleted the rails-set id. If I create a new employee and want to submit it, rails routes wrong, it still routes to [...]/employees/1 instead of [...]/employees/5000 (this is the personel_number).
First I thought, this problem might be simply solved by changing @employee = Employee.find(params[:id])
into @employee = Employee.find(params[:personel_number])
but this is not working:
ActiveRecord::RecordNotFound in EmployeesController#show
Couldn't find Employee without an ID
how can I solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论