MENU

Rails 保存

rails データ保存

def create
  @post = Post.new(post_params)

  if @post.save
    flash[:success] = "保存に成功"
    redirect_to posts_path
  else
    flash[:error] = "保存に失敗"
     redirect_to new_post_path
  end
end

例外などについては、こちらの動画で解説されている

www.youtube.com