我在Rails上全新。我试图通过在youtube上播放视频来建立论坛来学习它。
然而,我陷入了错误,只是不知道如何解决它。我一直在"未定义的方法'保存'为零。
代码:
控制器
class PostsController < ApplicationController
def index
end
def new
@post = Post.new
end
def create
@post = Post.new[post_params]
if @post.save
flash[:success] = "Saved"
redirect_to action: :show
else
flash[:error] = "There was a problem adding"
render action: :new
end
end
def post_params
params[:post].permit(:title, :content)
end
new.html.haml
%h1 New post
= render 'form'
_form.html.haml
= simple_form_for @post do |f|
= f.input :title
= f.input :content
= f.submit
CreatePosts
class CreatePosts < ActiveRecord::Migration[5.1]
def change
create_table :posts do |t|
t.string :title
t.text :content
t.timestamps
end
end
end
有人知道这里出了什么问题吗?
答案 0 :(得分:2)