当我在下面的代码中尝试替换@post.update时@post.save,它仍然有效并返回true,但值未更新.
def create
@post = Post.new(post_params)
if @post.save
redirect_to posts_path, notice: 'Post was successfully created.'
else
render action: 'new'
end
end
def update
respond_to do |format|
if @post.update(post_params)
format.html { redirect_to @post, notice: 'Post was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'new' }
format.json { render json: @post.errors, status: :unprocessable_entity }
end
end
end
Run Code Online (Sandbox Code Playgroud)
以下是我的佣金路线:
$ rake routes
posts GET /posts(.:format) posts#index
POST /posts(.:format) posts#create
new_post GET /posts/new(.:format) posts#new …Run Code Online (Sandbox Code Playgroud)