[英]Rails Polymorphic Association, causing 'nil is not a symbol' TypeError from form_for when trying to create new
User Model 用户模型
belongs_to :role, :polymorphic => true
admin_profile model (NOT ACTUAL NAME, BUT YOU GET THE IDEA) admin_profile模型(不是实际名称,但你得到了想法)
has_one :user, :as => :role
user_profile model (NOT ACTUAL NAME, BUT YOU GET THE IDEA. There are others beyond these two.) user_profile模型(不是实际名称,但你得到了这个想法。除了这两个之外还有其他人。)
has_one :user, :as => :role
When I visit /admin_profile/new, I get 'nil is not a symbol' TypeError on line #1. 当我访问/ admin_profile / new时,我在第1行上得到'nil不是符号'TypeError。
<%= form_for(@admin_profile) do |f| %>
...
The contents of @admin_profile are: @admin_profile的内容是:
<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. 如果还有其他信息需要,请告诉我。
The problem was some of the tables had :id => false. 问题是一些表有:id => false。 Let this be a warning to would be users of db:schema:dump 让这成为db:schema:dump用户的警告
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.