What happens if the update or create fails? We need to ensure that our user is notified in case of failure:
Anti-pattern
post '/posts' do
@post = Post.new(params[:post)
@post.save
redirect "/posts"
end
Anti-Anti-Pattern:
post '/posts' do
@post = current_user.posts.build(params[:post)
if @post.save
redirect "/posts"
else
render :new, locals: { messages: [ "There was an error!", @post.errors.full_messages ] }
end
end