奇怪的AbstractController :: ActionNotFound错误与Rails中的更新方法 [英] Strange AbstractController::ActionNotFound Error with update method in Rails

查看:169
本文介绍了奇怪的AbstractController :: ActionNotFound错误与Rails中的更新方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 FamiliesController ,具有以下操作:

def edit
 @family=Family.find(params[:id])
end

def update
    @family=Family.find(params[:id])
    @family.update_attributes(params[:family])
end   

家庭模式 :(使用Mongoid)

Family model: (Using Mongoid)

attr_accessible :location
field :location  

edit.html.erb

<div class="container">
<%= form_for @family do |f| %>
  <%= f.error_messages %>
  <p>
    <%= f.label :location %><br />
    <%= f.text_field :location %>
  </p>
<%= f.submit "Submit" %>
</div>  

rotues.rb

resources :families  

但是当我提交我得到的形式是

But when I submit the form I get:


AbstractController :: ActionNotFound位于/ families / 5235513e1dba7f8605000004

AbstractController::ActionNotFound at /families/5235513e1dba7f8605000004

找不到FamiliesController的操作'5235513e1dba7f8605000004'

The action '5235513e1dba7f8605000004' could not be found for FamiliesController

(5235513e1dba7f8605000004)是该人的ID

(5235513e1dba7f8605000004) is id of the person

这是怎么了?

编辑

因此,我在SO上发现了 Rails不支持字母数字ID 的问题,答案中提到的gem在mongoid中也不起作用(它们仅适用于ActiveRecord模型)。那么如何为Mongoid解决这个问题呢?

So I found out on SO and it looks like Rails does not support alphanumeric IDs Also the gem mentioned in the answers don't work in mongoid (they are only for ActiveRecord models). So how to sort out this issue for Mongoid?

这是否意味着我无法使用Rails更新方法更新Mongoid中的数据库记录?

推荐答案

我移动了


资源:家庭

resources :families

routes.rb 的顶部。现在工作正常。

to top of the routes.rb. And now it works fine.

不要不这样做。

这篇关于奇怪的AbstractController :: ActionNotFound错误与Rails中的更新方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆