I have a small Ruby on Rails application that I am trying to refactor and in the process have broken the abilty to save some data. I have literally spent the entire day trying to sort this out (I am a Rails newbie, basically restricted to trying to improve an app I already have).
I have Documents which have have locations associated with them:
class Document < ActiveRecord::Base
has_many :locations, :dependent => :destroy
end
class Location < ActiveRecord::Base
belongs_to :document
end
I can edit Locations that have already been added to the Document (this is from documents/locations.html):
<% @locations.each do |location| %>
<% unless location.new_record? %>
<%@location = location%>
<%= form_for(@location,:url=>document_location_path(@document,@location),:method=>:put) do |f| %>
<%= render :partial => "document_locations/form", :locals => {:f => f } %>
<% end %>
<% end %>
<% end %>
But attempts to add new Locations don't error, but don't add save either
<% @location = @document.locations.new %>
<%= form_for(@location,:url=>:document_locations, :method=>:post) do |f| %>
<%= render :partial => "document_locations/form", :locals => {:f => f } %>
<%end%>
When I rake routes, I see the following
document_locations /documents/:document_id/locations(.:format) {:controller=>"documents", :action=>"locations"}
document_document_locations GET /documents/:document_id/document_locations(.:format) {:action=>"index", :controller=>"document_locations"}
POST /documents/:document_id/document_locations(.:format) {:action=>"create", :controller=>"document_locations"}
new_document_document_location GET /documents/:document_id/document_locations/new(.:format) {:action=>"new", :controller=>"document_locations"}
edit_document_document_location GET /documents/:document_id/document_locations/:id/edit(.:format) {:action=>"edit", :controller=>"document_locations"}
document_document_location GET /documents/:document_id/document_locations/:id(.:format) {:action=>"show", :controller=>"document_locations"}
PUT /documents/:document_id/document_locations/:id(.:format) {:action=>"update", :controller=>"document_locations"}
DELETE /documents/:document_id/document_locations/:id(.:format) {:action=>"destroy", :controller=>"document_locations"}
I'm guessing my routes and controllers are in a right old mess, but any suggestions as to how I could start to trouble shoot would be appreciated.
development.log shows this when I attempt to add a location:
Started POST "/documents/210/locations" for 127.0.0.1 at 2012-11-04 23:14:16 +0000
DEPRECATION WARNING: class_inheritable_attribute is deprecated, please use class_attribute method instead. Notice their behavior are slightly different, so refer to class_attribute documentation first. (called from acts_as_taggable_on at /home/christian/Documents/business/development/pastpaper/vendor/plugins/acts-as-taggable-on/lib/acts_as_taggable_on/acts_as_taggable_on.rb:34)
Processing by DocumentsController#locations as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"OEsBVZPX8NznM0oO/O38/BSrjlpJrNV7oEZTWTcQV9c=", "location"=>{"street1"=>"xian1", "street2"=>"xian2", "town"=>"xian3", "county"=>"", "state"=>"", "country"=>""}, "commit"=>"Save", "document_id"=>"210"}
Document Load (0.6ms) SELECT `documents`.* FROM `documents` WHERE `documents`.`id` = 210 LIMIT 1
DocumentAttribute Load (0.6ms) SELECT `document_attributes`.* FROM `document_attributes` WHERE `document_attributes`.`document_id` IN (210)