Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class PostsController < SiteController
- def update
- if @type == 'Answer'
- @post = Answer.find_by_parent_id(params[:id])
- else
- @post = Message.find(params[:id])
- end
- respond_to do |format|
- else
- # post attributes
- @post.attributes = params[:post]
- if @type == 'Answer' && params[:post] && params[:post][:addressee_id]
- addressee = @post.message.site.addressees.find_by_id(params[:post][:addressee_id])
- @post.addressee = addressee if addressee
- end
- ... resource stuff ...
- # need to resource.valid? because its already saved above
- if @post.save && @post.resources.all?{|r| r.valid?}
- flash[:unpublished_post] = @post.id if !@post.published && @post.author.is_a?(AnonymousAuthor)
- flash[:notice] = "#{@type} updated."
- format.html { redirect_to( ( @type == 'Message' ? message_path(:id => @post.id) : message_path(:id => @post.parent_id) ) ) }
- else
- format.html do render :action => 'edit'
- initialize_resources
- set_form_params
- end
- format.js do
- render :nothing => true, :status => 500
- end
- end
- end
- end
- rescue AuthError
- msg = "You don't have the rights to edit that post. Your attempt has been logged."
- respond_to do |wants|
- wants.html { flash[:notice] = msg; redirect_back_or_default(message_path(:id => message)) }
- wants.js { render :text => msg, :status => 400 }
- end
- end
- end
Add Comment
Please, Sign In to add comment