'无法将符号转换为整数' - Simple_Form和Devise的问题

时间:2013-07-16 00:29:02

标签: ruby-on-rails devise simple-form typeerror

我收到以下错误:

设计/注册中的TypeError #new 动作控制器:异常捕获 - 无法将符号转换为整数

当我在下面添加**'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'

2 个答案:

答案 0 :(得分:0)

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

has_many :rounds
has_many :judges

答案 1 :(得分:0)

如果我错了,请原谅我,但是roundsjudges是两个不同的表,对吗?

他们都与competitions没有范围关联,对吗?

如果是这种情况,您的has_many课程中的Competition关联应该有2条不同的行,例如:

class Competition < ActiveRecord::Base
  attr_accessible :name
  has_many :rounds
  has_many :judges
end