在 Rails 控制器代码中
def create
@post = Post.new(params[:post])
@post.random_hash = generate_random_hash(params[:post][:title])
if @post.save
format.html { redirect_to @post }
else
format.html { render action: "new" }
end
end
定义的前两行是否应该放在里面if @post.save
?如果post没有保存,创建的Post对象Post.new
还会存入数据库吗?