Hi,
I’ve got a small problem with my validation of a model. I have a user
and a user_setting table. The user has all main informations and the
user_setting - table has addional data like his first name etc. All
necessary input field are in one form and connect with field_for to the
right model. All possible input fields of the user_setting table are
saved in a configuration file. If the form will be submitted the
user_setting model check the value of the input fields with the given
informations of the configuration file. Now is my problem that message
in combination with the Globalite - plugin allways repeat
“localization_missing” and not the right message of the
check_settings - method. Antoher problem is that the input field of
user_setting model are not red marked in the create form.
My Model:
class UserSetting < ActiveRecord::Base
validate :check_settings
belongs_to :user, :foreign_key => “user_id”
validates_presence_of :name, :message => :message_insert_name.l
validates_presence_of :setting_type, :message => “Include type”
protected
def check_settings
yaml_settings =
LoadConfigurations.load_configurations(“user_settings”)
if yaml_settings[self.setting_type][self.name][‘necessary’] == 1
errors.add(self.name, :notice_no_value_set.l(“Error! No value
set!”)) if self.value.blank?
elsif !yaml_settings[self.setting_type][self.name][‘range’].blank?
end
end
end
Has anybody some tips to solve these problems?
Regards Eddy