1

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?

Muntasim
  • 6,689
  • 3
  • 46
  • 69
  • I'm having the same problem.Hope someone helps! – mrudult Sep 16 '13 at 06:45
  • What is `5235513e1dba7f8605000004`? Is that the `id`? How come it is alphanumeric? – Rajesh Kolappakam Sep 16 '13 at 06:51
  • @RajeshKolappakam Yeah it is the id of the person I'm passing. Using mondoid. It's the id which Mongoid automatically creates on making a new object (in this case a Family). –  Sep 16 '13 at 06:54
  • 1
    if you are not trying something special with your model, it should work fine. alphanumeric id should not make any difference here. Could you please put your family.rb code here and also routes if possible. I just tried a demo app with mongoid, it works as expected – Muntasim Sep 20 '13 at 12:51
  • 2
    using alphanumeric ids shouldn't cause any problems. it seems something is wrong with your routes. – Fenec Sep 20 '13 at 23:13
  • try 1. to put your resources :families to the top of routes.rb 2. check if your form is really sending a PUT request, not POST – Fenec Sep 20 '13 at 23:22

2 Answers2

1

I moved the

resources :families

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

Don't no why it is so.

0

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:

Community
  • 1
  • 1
Rajesh Kolappakam
  • 2,095
  • 14
  • 12