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對象仍將放入數據庫中?
你的解釋很清楚。謝謝! –