我收到以下错误:
设计/注册中的TypeError #new 动作控制器:异常捕获 - 无法将符号转换为整数
当我在下面添加**'ed f.association行时,我开始收到此错误。
这让我很困惑,因为我已经遵循了Rails指南协会文档以及simple_form文档:
<%= simple_form_for @user do |f| %>
<%= f.input :name %>
<%= f.association :company %>
<%= f.association :roles %>
<%= f.button :submit %>
<% end %>
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), html: { class: 'form-horizontal'}) do |f| %>
<%= f.error_notification %>
<%= f.input :email %>
<%= f.input :password %>
<%= f.input :password_confirmation %>
**<%= f.association :competition %>**
<div class="form-actions">
<%= f.submit "Sign up", class: "btn btn-primary" %>
</div>
<% end %>
<%= render "devise/shared/links" %>
class Competition < ActiveRecord::Base
attr_accessible :name
has_many :rounds, :judges
end
class Judge < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
attr_accessible :email, :password, :password_confirmation, :remember_me, :name
belongs_to :competition
end
class AddAssocToJudges < ActiveRecord::Migration
def up
change_table :judges do |t|
t.belongs_to :competition
end
end
end
app/models/competition.rb:4:in `<class:Competition>'
app/models/competition.rb:1:in `<top (required)>'
app/views/devise/registrations/new.html.erb:9:in `block in _app_views_devise_registrations_new_html_erb__3768524909032037243_70228371062560'
app/views/devise/registrations/new.html.erb:3:in `_app_views_devise_registrations_new_html_erb__3768524909032037243_70228371062560'
答案 0 :(得分:0)
您只需要在不同的行中定义has_many
:
has_many :rounds
has_many :judges
答案 1 :(得分:0)
如果我错了,请原谅我,但是rounds
和judges
是两个不同的表,对吗?
他们都与competitions
没有范围关联,对吗?
如果是这种情况,您的has_many
课程中的Competition
关联应该有2条不同的行,例如:
class Competition < ActiveRecord::Base
attr_accessible :name
has_many :rounds
has_many :judges
end