Skip to content

Instantly share code, notes, and snippets.

@eileencodes
Created January 11, 2012 22:05
Show Gist options
  • Save eileencodes/1597034 to your computer and use it in GitHub Desktop.
Save eileencodes/1597034 to your computer and use it in GitHub Desktop.
class Admin::PostsController < Admin::AdminController
#only showing the update method
def update
@post = Post.find(params[:id])
if @post.valid?
add_author_to_post
save_or_remove_post_categorization
end
respond_to do |format|
if @post.update_attributes(params[:post])
format.html { redirect_to [ :edit_admin_post ], :notice => 'Post was successfully updated.' }
else
format.html { render :action => "edit" }
end
end
end
#method created for adding user to posts table
def add_author_to_post
@user = User.find_by_id(session[:user_id])
@user.posts << @post
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment