Strange AbstractController::ActionNotFound Error w

2019-02-20 18:27发布

I have FamiliesController with these actions:

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

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

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 at /families/5235513e1dba7f8605000004

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

(5235513e1dba7f8605000004) is id of the person

What is wrong here?

EDIT

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?

Does that mean I cannot use the Rails update method to update my database records in Mongoid?

2条回答
做个烂人
2楼-- · 2019-02-20 18:40

Rails does not support alphanumeric IDs by default, it expects an integer.

If you need to make the IDs alphanumeric, you need to make some changes. Please look at the following resources:

查看更多
再贱就再见
3楼-- · 2019-02-20 18:52

I moved the

resources :families

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

Don't no why it is so.

查看更多
登录 后发表回答