The problem is that the instance variable @it_should
which you set with the attr_accessor
is not persisted between requests, so although you set it to true
in your new
action, it will be reset as soon as the form is submitted and some other action (probably create
or update
) is triggered.
If you want to validate a field this way, you'd have to set it in the action triggered by the form submission, e.g. create
:
def create
@something = Something.new(params[:something])
@something.it_should = true
@something.save
...
end
This should trigger the validation on name
as expected.