1
在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.new
创建的Post对象仍将放入数据库中?
你的解释很清楚。谢谢! –