On Tuesday, May 26, 2015 at 9:13:57 PM UTC-7, Jon Mattingly wrote:
>
> I'm trying to set up validations for a couple of my models, and would like 
> to use a custom error message. However, sequel validations add the column 
> name before the message. 
>

That's not really true.  Only Sequel::Model::Errors#full_messages adds the 
column name before the message, and only if the message is not a literal 
string.  If you do obj.errors.on(:column), you get whatever error message 
was used, without the column name added. If you want different behavior, 
you should override full_messages.  You can override Model#errors_class for 
the model to return a subclass of Sequel::Model::Errors that has a 
different implementation of full_messages.
 

> So if I do a validates_unique on the :username column, it will say 
> 'username is taken' or whatever the message is I specify. I'd like to 
> remove the username part of it and just return :message.
>
> I saw an example in the docs for  'errors.add(:name, Sequel.lit("Album 
> name is not valid"))' but that seems like a mass solution with no way to 
> limit it to a validates_unique error. I'd only want to do it for some 
> columns.
>

That's not a mass solution, that's a specific solution for the cases where 
you don't want the column named automatically added by full messages.  If 
you only want to do that for some columns and not others, just use 
Sequel.lit for the columns where you don't want the name automatically 
added.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to