我有3个模型:用户,样本+颜色。用户有许多样例,样例引用一种颜色。
用户在其配置文件页面(Users/show/id)上创建样例。
颜色模型通过样例模型处理验证
accepts_nested_attributes_for :color
和
validates_associated :color
.
我的问题是,如何在用户配置文件页面上显示特定于颜色的验证错误?
class SwatchesController < ApplicationController
before_filter :authenticate
def create
color = Color.find_or_create_by_value(params[:swatch][:colors][:value])
@swatch = current_user.swatches.build(:color_id => color.id)
if @swatch.save
flash[:success] = "Swatch created"
redirect_to user_path(current_user)
else
flash[:error] = "Error"
redirect_to user_path(current_user)
end
end
end