Validations In Controller Actions Lab
class Author < ActiveRecord::Base
validates :name, presence: true
validates :email, uniqueness: true
end
class Post < ActiveRecord::Base
validates :title, presence: true
validates :category, inclusion: { in: ["Fiction", "Non-Fiction"]}
validates :content, length: { minimum: 100 }
end
def update
if @post.update(post_params)
redirect_to post_path(@post)
else
render :edit
end
end
def create
@author = Author.new(author_params)
if @author.valid?
@author.save
redirect_to author_path(@author)
else
render :new
end
end