I have created a simple has_many and belongs_to relationship between two activerecords and when i try to create uninitialized constant Tool::Version,

tool.rb:

class Tool < ActiveRecord::Base
  attr_accessible :name
  validates_presence_of :name
  has_many :versions
end

versions.rb

class Versions < ActiveRecord::Base
  belongs_to :tool
  attr_accessible :tool_version
end

abc.html.erb:

<%= form_for([@tool, @tool.versions.build]) do |f| %>
    <div class="field">
        <%= f.label :version %><br />
        <%= f.text_field :version %>
    </div>
    <div class="actions">
        <%= f.submit %>     
    </div>

<% end %>

on submit I get the error. what am i doing wrong here??

有帮助吗?

解决方案

Your text_field should be tool_version and not version

其他提示

You should change the class name

The class name should be Version, not Versions

class Versions < ActiveRecord::Base
  belongs_to :tool
  attr_accessible :tool_version
end
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top