Janko
Janko

Reputation: 9335

Is it possible to do validations in Rails depending on the current locale

I'm working on a bilingual Rails application. I have a model Application, which represents an applicant to a certain course (if a person wants to participate, he/she fills in the application form, and that is saved into the database). The problem is, the form should look a bit different in English than in Croatian (those are the 2 languages). I would normally have to tables for this purpose, but the difference is really small, so I don't want to.

So, this means that I have to have different validations depending on whether the applicant submitted the croatian or the english form. Is there a way I can do that?

Upvotes: 1

Views: 61

Answers (1)

Yuri  Barbashov
Yuri Barbashov

Reputation: 5437

You can use if or unless option for validation

validates :something, presence: true, if: ->(){ language == "en" }

language could be virtual attribute defined in your model which you can pass in form params

Upvotes: 1

Related Questions