验证错误显示正在为 :category:Symbol' 生成此 'undefined method `full_message'
Validation error display is producing this 'undefined method `full_message' for :category:Symbol'
我正在按照 Rails Guide 来实现这个,但是我遇到了这个错误,而且我不完全确定如何修复它。
表格显示错误:
<% if @group.errors.any? %>
<div id="error_exp">
<h2><%= pluralize(@group.errors.count, "error") %> prohibited this article from being saved:</h2>
<ul>
<% @group.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>
控制器创建操作:(我正在测试新组表单上的错误显示)
def create
@group = current_user.groups.build(group_params)
if @group.save
redirect_to user_groups_path(current_user)
else
render :new
end
end
模型验证:
class Group < ApplicationRecord
has_many :cards, dependent: :destroy
belongs_to :category
belongs_to :user
end
class Category < ApplicationRecord
has_many :groups
has_many :users, through: :groups
validates :name, presence: true
validates_uniqueness_of :name, :case_sensitive => false
end
class Card < ApplicationRecord
belongs_to :group
validates :front,:back, presence: true
end
感谢您的帮助!
我正在按照 Rails Guide 来实现这个,但是我遇到了这个错误,而且我不完全确定如何修复它。
表格显示错误:
<% if @group.errors.any? %>
<div id="error_exp">
<h2><%= pluralize(@group.errors.count, "error") %> prohibited this article from being saved:</h2>
<ul>
<% @group.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>
控制器创建操作:(我正在测试新组表单上的错误显示)
def create
@group = current_user.groups.build(group_params)
if @group.save
redirect_to user_groups_path(current_user)
else
render :new
end
end
模型验证:
class Group < ApplicationRecord
has_many :cards, dependent: :destroy
belongs_to :category
belongs_to :user
end
class Category < ApplicationRecord
has_many :groups
has_many :users, through: :groups
validates :name, presence: true
validates_uniqueness_of :name, :case_sensitive => false
end
class Card < ApplicationRecord
belongs_to :group
validates :front,:back, presence: true
end
感谢您的帮助!