I am newbie in rails and want to apply validation on form fields.
myviewsnew.html.erb
<%= form_for :simulation, url: simulations_path do |f| %>
<div class="form-group">
<%= f.label :Row %>
<div class="row">
<div class="col-sm-2">
<%= f.text_field :row, class: 'form-control' %>
</div>
</div>
</div>
.....
Simulation.rb
class Simulation < ActiveRecord::Base
belongs_to :user
validates :row, :inclusion => { :in => 1..25, :message => 'The row must be between 1 and 25' }
end
I want to check the integer range of row field in model class and return the error message if it's not in the range. I can check the range from above code but not able to return the error message
Thanks in advance
Aucun commentaire:
Enregistrer un commentaire