RailsCasts Pro episodes are now free!
Learn more or hide this
Resources
gem 'active_attr'
class Message include ActiveAttr::Model attribute :name attribute :email attribute :content attribute :priority # type: Integer, default: 0 attr_accessible :name, :email, :content validates_presence_of :name validates_format_of :email, :with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i validates_length_of :content, :maximum => 500 end
m = Message.new(priority: 1) m.priority m.priority = 1 m.priority?
def new @message = Message.new end def create @message = Message.new(params[:message]) if @message.valid? # TODO send message here redirect_to root_url, notice: "Message sent! Thank you for contacting us." else render "new" end end