Rails 多态关联,导致“nil 不是符号”;尝试创建新的表单时出现 TypeError
用户模型
belongs_to :role, :polymorphic => true
admin_profile 模型(不是实际名称,但您明白了)
has_one :user, :as => :role
user_profile 模型(不是实际名称,但您明白了。除了这两个之外还有其他模型。)
has_one :user, :as => :role
当我访问 /admin_profile/new 时,我得到 'nil is not第 1 行出现符号类型错误。
<%= form_for(@admin_profile) do |f| %>
...
@admin_profile 的内容是:
<AdminProfile id: nil, birth_date: nil, url: nil>
跟踪是这样的
activerecord (3.1.1) lib/active_record/attribute_methods/primary_key.rb:8:in `to_key'
actionpack (3.1.1) lib/action_controller/record_identifier.rb:76:in `record_key_for_dom_id'
actionpack (3.1.1) lib/action_controller/record_identifier.rb:57:in `dom_id'
actionpack (3.1.1) lib/action_view/helpers/form_helper.rb:388:in `apply_form_for_options!'
actionpack (3.1.1) lib/action_view/helpers/form_helper.rb:365:in `form_for'
如果需要任何其他信息,请告诉我。
User Model
belongs_to :role, :polymorphic => true
admin_profile model (NOT ACTUAL NAME, BUT YOU GET THE IDEA)
has_one :user, :as => :role
user_profile model (NOT ACTUAL NAME, BUT YOU GET THE IDEA. There are others beyond these two.)
has_one :user, :as => :role
When I visit /admin_profile/new, I get 'nil is not a symbol' TypeError on line #1.
<%= form_for(@admin_profile) do |f| %>
...
The contents of @admin_profile are:
<AdminProfile id: nil, birth_date: nil, url: nil>
The trace goes like this
activerecord (3.1.1) lib/active_record/attribute_methods/primary_key.rb:8:in `to_key'
actionpack (3.1.1) lib/action_controller/record_identifier.rb:76:in `record_key_for_dom_id'
actionpack (3.1.1) lib/action_controller/record_identifier.rb:57:in `dom_id'
actionpack (3.1.1) lib/action_view/helpers/form_helper.rb:388:in `apply_form_for_options!'
actionpack (3.1.1) lib/action_view/helpers/form_helper.rb:365:in `form_for'
If there is any other information required, let me know.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是某些表有 :id =>错误的。这是对 db:schema:dump 用户的警告
The problem was some of the tables had :id => false. Let this be a warning to would be users of db:schema:dump