Skip to content

Instantly share code, notes, and snippets.

@BrayanZ
Created April 29, 2013 04:54
Show Gist options
  • Save BrayanZ/5479773 to your computer and use it in GitHub Desktop.
Save BrayanZ/5479773 to your computer and use it in GitHub Desktop.
# Update the attributes of a post/article/kata, and generate a notice if the changes could
# be saved or retry to edit otherwise.
# The attributes to be saved are different between Post and Kata.
# For Post, tags and source url need to be saved.
# For Kata, categories, challenge level and source url need to be saved.
def update
@post = post_type.find_by_slug(params[:id])
authorize! :update, @post
@form = params[@type.downcase.to_sym]
if post_type == Post
@post.tempTags = @form[:tempTags]
@post.setTags
@post.source_url = params[@type.downcase.to_sym][:source_url]
elsif post_type == Kata
@post.category_ids = @form[:category_tokens].to_s.split(",")
@post.challenge_level = @form[:challenge_level]
@post.source_url = params[@type.downcase.to_sym][:source_url]
end
@post.title = @form[:title]
@post.content = params[@type.downcase.to_sym][:content]
respond_to do |format|
if @post.save
format.html { redirect_to(@post, :notice => "#{@type} was successfully updated.") }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @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