Created
August 26, 2014 12:01
-
-
Save rishighan/fd486836e87cde359478 to your computer and use it in GitHub Desktop.
update action in posts controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def update | |
respond_to do |format| | |
case params[:commit] | |
when "Save Draft" | |
@post.update_attribute(:is_draft, "yes") | |
format.html { redirect_to @post, notice: 'Post was successfully updated.' } | |
format.json { head :no_content } | |
when "Update Post" | |
@post.update_attribute(:is_draft, "no") | |
format.html { redirect_to @post, notice: 'Post was successfully updated.' } | |
format.json { head :no_content } | |
else | |
format.html { render :action => "edit" } | |
format.json { render :json => @post.errors, :status => :unprocessable_entity } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The update action takes an id.
As opposed to the update_attributes method that assumes you are already working with the object.
So something like
should work, given that you get the @post.id from the form you are working with and
post_params
is the whitelisted set of attributes you want to update thePost
model with.