Skip to content

Commit

Permalink
Fixed custom_field delete
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Tillman committed Nov 16, 2011
1 parent 278eb37 commit d757590
Showing 1 changed file with 2 additions and 27 deletions.
29 changes: 2 additions & 27 deletions app/controllers/admin/fields_controller.rb
Expand Up @@ -121,12 +121,10 @@ def update
# DELETE /fields/1.xml HTML and AJAX
#----------------------------------------------------------------------------
def destroy
@custom_field = CustomField.find(params[:id])
@custom_field.destroy if @custom_field
@field = CustomField.find(params[:id])

respond_to do |format|
format.html { respond_to_destroy(:html) }
format.js { respond_to_destroy(:ajax) }
format.js # destroy.js.rjs
format.xml { head :ok }
end

Expand All @@ -137,27 +135,4 @@ def destroy
# POST /fields/auto_complete/query AJAX
#----------------------------------------------------------------------------
# Handled by before_filter :auto_complete, :only => :auto_complete

private

#----------------------------------------------------------------------------
def respond_to_destroy(method)
if method == :ajax
if called_from_index_page?
@fields = get_fields
if @fields.blank?
@fields = get_fields(:page => current_page - 1) if current_page > 1
render :action => :index and return
end
else
self.current_page = 1
end
# At this point render destroy.js.rjs
else
self.current_page = 1
flash[:notice] = "#{@custom_field.field_name} has beed deleted."
redirect_to(fields_path)
end
end
end

0 comments on commit d757590

Please sign in to comment.