Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在RubyonRails中保存模型失败。更新工作正常_Ruby On Rails - Fatal编程技术网

Ruby on rails 在RubyonRails中保存模型失败。更新工作正常

Ruby on rails 在RubyonRails中保存模型失败。更新工作正常,ruby-on-rails,Ruby On Rails,我有一个小的RubyonRails应用程序,我正在尝试重构它,在这个过程中,它破坏了保存一些数据的能力。我花了整整一天的时间试图解决这个问题(我是一个Rails新手,基本上只限于尝试改进我已有的应用程序) 我有一些文件,这些文件有与其相关的位置: class Document < ActiveRecord::Base has_many :locations, :dependent => :destroy end class Location < ActiveReco

我有一个小的RubyonRails应用程序,我正在尝试重构它,在这个过程中,它破坏了保存一些数据的能力。我花了整整一天的时间试图解决这个问题(我是一个Rails新手,基本上只限于尝试改进我已有的应用程序)

我有一些文件,这些文件有与其相关的位置:

class Document < ActiveRecord::Base   
  has_many :locations, :dependent => :destroy
end

class Location < ActiveRecord::Base
  belongs_to :document
end
我猜我的路线和管制员正处于一个正确的旧混乱中,但任何关于如何开始故障排除的建议都将不胜感激

development.log在我尝试添加位置时显示:

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)

如我所见,为该位置生成的资源路由包含一个必须存在的文档id。我假设您将位置资源路由定义为文档路由的嵌套。因此:

<%= form_for(@location,:url=>:document_locations, :method=>:post) do |f| %>
:document_locations,:method=>:post)do | f |%>
看起来不完整,因为您没有将文档传递到路由。尝试:

<%= form_for(@document, @location) do |f| %>


尝试在某个地方产生错误。在开发模式下应该足够详细。显示LocationsController和发布到创建操作的日志输出会很有帮助。感谢您的评论-我已经在问题中发布了development.log的输出。那有用吗?谢谢你,楚克。它返回的参数数
错误(1代表0)
对不起,调用错误,我是说(@location)do | f的form|u(post和url是推断出来的。但这并不能解决您的问题。发布日志错误,请注意,这种方式很难。只是如上所述进行了更改,并为#``使用了以下错误
未定义的方法
locations_path'。我在哪里可以找到日志错误?目前生成的唯一日志是development。loghumm…检查此项:。我不知道您是如何定义的。)对路线进行了罚款,但其中一种变体应该有效。。。
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)
<%= form_for(@location,:url=>:document_locations, :method=>:post) do |f| %>
<%= form_for(@document, @location) do |f| %>