Difference between 'save' and 'update' in using with different http requests

ruby-on-rails

Solution

Because `save` will not accept the attributes as parameters; `save` can only accept parameters like `validate: false` to skip validation.

If you want to use `save`, then you need to assign or modify individual attributes before `save`. But if you want mass-assignment, `update` would be your choice.

@post.f_name = 'foo'
@post.l_name = 'bar'    
@post.update # This will not work
@post.save # This will work

@post.save({:f_name=>"peter",:l_name=>"parker"}) # This will not work
@post.update({:f_name=>"peter",:l_name=>"parker"}) # This will work

Problem

When I tried replacing `@post.update` with `@post.save` as in my code below, it still worked and it returned true, but the values were not updated. ``` 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 ``` below are my rake routes: ``` $ rake routes posts GET /posts(.:format) posts#index POST /posts(.:format) posts#create new_post GET /posts/new(.:format) posts#new edit_post GET /posts/:id/edit(.:format) posts#edit post GET /posts/:id(.:format) posts#show PATCH /posts/:id(.:format) posts#update PUT /posts/:id(.:format) posts#update DELETE /posts/:id(.:format) posts#destroy root / welcome#index ``` Why didn't it update or overwrite my record? Will using different http requests for the same methods have any effect on them? Can we use `PUT`, `GET`, `PATCH` and `DELETE` for save when passed with proper syntax? The question is regarding rails 4 guide, the first guide.

Original source