0

我收到以下错误:

设计/注册#new Action Controller 中的 TypeError:异常捕获 - 无法将符号转换为整数

当我在下面添加 **'ed f.association 行时,我开始收到此错误。

这让我很费解,因为我遵循了 Rails 指南关联文档以及 simple_form 文档:

Simple_Form 示例

<%= simple_form_for @user do |f| %>
  <%= f.input :name %>
  <%= f.association :company %>
  <%= f.association :roles %>
  <%= f.button :submit %>
<% end %>

我的 Simple_Form 执行

<%= 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'
4

2 回答 2

0

您只需要has_many在不同的行中定义:

has_many :rounds
has_many :judges
于 2013-07-16T00:33:28.543 回答
0

如果我错了,请原谅我,但是rounds并且judges是 2 个不同的表,对吗?

而且它们都与competitions没有范围的关联,对吗?

如果是这种情况,您应该has_many在课堂上为您的关联设置 2 条不同的行Competition,例如:

class Competition < ActiveRecord::Base
  attr_accessible :name
  has_many :rounds
  has_many :judges
end
于 2013-07-16T00:33:36.853 回答