I have a routing mystery in Rails 3.0.10 using Formtastic 1.2.4.

The history resources are nested within the patient resources. I want
to edit one field of a history record for a particular patient (so I'm
not dealing with updating patient and history together, just history).
The field ('results') contains yaml-ized data, but that's not the
issue here.

The problem is that the route for updating a history record is not
recognized by Rails. The route for creating a new record works fine,
as do all the other related routes. But hitting "Submit" on the edit
form gives an error.

files:
controllers/
  patients/
    histories_controller.rb  (class Patients::HistoriesController)

routes.rb:
resources :patients do
  resources  :histories,  :module => "patients" # (necessary because
of namespacing of controller)

rake routes:
   patient_histories GET    /patients/:patient_id/
histories(.:format)
{:action=>"index", :controller=>"patients/histories"}
                     POST   /patients/:patient_id/
histories(.:format)
{:action=>"create", :controller=>"patients/histories"}
 new_patient_history GET    /patients/:patient_id/histories/
new(.:format)       {:action=>"new", :controller=>"patients/
histories"}
edit_patient_history GET    /patients/:patient_id/histories/:id/
edit(.:format)  {:action=>"edit", :controller=>"patients/histories"}
     patient_history GET    /patients/:patient_id/
histories/:id(.:format)       {:action=>"show", :controller=>"patients/
histories"}
                     PUT    /patients/:patient_id/
histories/:id(.:format)
{:action=>"update", :controller=>"patients/histories"}
                     DELETE /patients/:patient_id/
histories/:id(.:format)
{:action=>"destroy", :controller=>"patients/histories"}

_form.haml:
  = semantic_form_for @results, :url => url do |f|
    = f.inputs do
    ...
    = f.buttons do
      = f.commit_button

new.haml:
= render :partial => "form",
  :locals => { :url => patient_histories_path(@patient), ...

produces HTML:
<form accept-charset="UTF-8" action="/patients/9/histories"

Clicking on "Submit" produces

Started POST "/patients/9/histories" for 127.0.0.1 at 2011-09-04
15:30:04 -0700
  Processing by Patients::HistoriesController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"...",
"result"=>{...}, "patient_id"=>"9"}

which successfully creates a new history record.

But,

edit.haml:
= render :partial => "form",
  :locals => { :url => patient_history_path(@patient, @history), ...

produces HTML:
<form accept-charset="UTF-8" action="/patients/9/histories/102"  ...

Clicking on "Submit" in this last form produces

Started POST "/patients/9/histories/103" for 127.0.0.1 at 2011-09-04
15:28:46 -0700
ActionController::RoutingError (No route matches "/patients/9/
histories/103"):

WTF?

I've tried putting  :button_html => { :method => "put" }  in the
commit_button line, without effect.

Anybody with a clue, shout out, thanks!

Scott

-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby

Reply via email to