'Rails 5 - Custom validation with one error message

I want to add multiple conditions to valid but i want to view only one summary error message.

validates :floor, presence: true, numericality: { only_integer: true }, length: { maximum: 2 }

How show only one message whenever having any error, like: "Floor is required, must be number..."

In addition, when i use :

if @posts.valid?
   @posts.save
   redirect_to room_path
else
   render :new
end

Browser will render new with message but url is http://localhost:3000/posts, it is not http://localhost:3000/posts/new This is a problem when user refresh page => it will return index page (not new page). How can i fix it ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source