Skip to content

Commit

Permalink
Fixed deprecations in search with how we used acts_as_indexed - updat…
Browse files Browse the repository at this point in the history
…ed to with_query from find_with_index.
  • Loading branch information
parndt committed Aug 2, 2010
1 parent abfad38 commit 55be5ee
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 48 deletions.
16 changes: 8 additions & 8 deletions vendor/plugins/images/app/controllers/admin/images_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ class Admin::ImagesController < Admin::BaseController

include Admin::ImagesHelper

crudify :image, :order => "created_at DESC", :conditions => "parent_id is NULL", :sortable => false
crudify :image,
:order => "created_at DESC",
:conditions => "parent_id is NULL",
:search_conditions => "parent_id IS NULL",
:sortable => false

before_filter :change_list_mode_if_specified, :init_dialog

def index
if searching?
@images = Image.paginate_search params[:search],
:page => params[:page],
:order => "created_at DESC",
:conditions => "parent_id IS NULL"
search_and_paginate_all_images
else
@images = Image.paginate :page => params[:page],
:order => "created_at DESC",
:conditions => "parent_id IS NULL"
paginate_all_images
end

if RefinerySetting.find_or_set(:group_images_by_date_uploaded, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ class Admin::InquiriesController < Admin::BaseController
before_filter :get_spam_count, :only => [:index, :spam]

def index
if searching?
@inquiries = Inquiry.ham.find_with_index params[:search]
end
@inquiries = Inquiry.ham.with_query(params[:search]) if searching?

@grouped_inquiries = group_by_date(Inquiry.ham)
end

def spam
if searching?
@inquiries = Inquiry.spam.find_with_index params[:search]
end
@inquiries = Inquiry.spam.with_query(params[:search]) if searching?

@grouped_inquiries = group_by_date(Inquiry.spam)
end
Expand Down
91 changes: 62 additions & 29 deletions vendor/plugins/refinery/lib/crud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def crudify(model_name, new_options = {})
}.merge!(new_options)

module_eval %(
before_filter :find_#{singular_name}, :only => [:update, :destroy, :edit, :show]
before_filter :find_#{singular_name},
:only => [:update, :destroy, :edit, :show]
def new
@#{singular_name} = #{class_name}.new
Expand All @@ -44,14 +45,18 @@ def new
def create
# if the position field exists, set this object as last object, given the conditions of this class.
if #{class_name}.column_names.include?("position")
params[:#{singular_name}].merge!({:position => ((#{class_name}.maximum(:position, :conditions => "#{options[:conditions]}")||-1) + 1)})
params[:#{singular_name}].merge!({
:position => ((#{class_name}.maximum(:position, :conditions => "#{options[:conditions]}")||-1) + 1)
})
end
if (@#{singular_name} = #{class_name}.create(params[:#{singular_name}])).valid?
unless request.xhr?
flash[:notice] = t('refinery.crudify.created', :what => "'\#{@#{singular_name}.#{options[:title_attribute]}}'")
flash[:notice] = t('refinery.crudify.created',
:what => "'\#{@#{singular_name}.#{options[:title_attribute]}}'")
else
flash.now[:notice] = t('refinery.crudify.created', :what => "'\#{@#{singular_name}.#{options[:title_attribute]}}'")
flash.now[:notice] = t('refinery.crudify.created',
:what => "'\#{@#{singular_name}.#{options[:title_attribute]}}'")
end
unless from_dialog?
unless params[:continue_editing] =~ /true|on|1/
Expand All @@ -70,7 +75,11 @@ def create
unless request.xhr?
render :action => 'new'
else
render :partial => "/shared/admin/error_messages_for", :locals => {:symbol => :#{singular_name}, :object => @#{singular_name}}
render :partial => "/shared/admin/error_messages_for",
:locals => {
:symbol => :#{singular_name},
:object => @#{singular_name}
}
end
end
end
Expand All @@ -82,9 +91,11 @@ def edit
def update
if @#{singular_name}.update_attributes(params[:#{singular_name}])
unless request.xhr?
flash[:notice] = t('refinery.crudify.updated', :what => "'\#{@#{singular_name}.#{options[:title_attribute]}}'")
flash[:notice] = t('refinery.crudify.updated',
:what => "'\#{@#{singular_name}.#{options[:title_attribute]}}'")
else
flash.now[:notice] = t('refinery.crudify.updated', :what => "'\#{@#{singular_name}.#{options[:title_attribute]}}'")
flash.now[:notice] = t('refinery.crudify.updated',
:what => "'\#{@#{singular_name}.#{options[:title_attribute]}}'")
end
unless from_dialog?
unless params[:continue_editing] =~ /true|on|1/
Expand All @@ -103,7 +114,11 @@ def update
unless request.xhr?
render :action => 'edit'
else
render :partial => "/shared/admin/error_messages_for", :locals => {:symbol => :#{singular_name}, :object => @#{singular_name}}
render :partial => "/shared/admin/error_messages_for",
:locals => {
:symbol => :#{singular_name},
:object => @#{singular_name}
}
end
end
end
Expand All @@ -117,39 +132,51 @@ def destroy
end
def find_#{singular_name}
@#{singular_name} = #{class_name}.find(params[:id], :include => %w(#{options[:include].join(' ')}))
@#{singular_name} = #{class_name}.find(params[:id],
:include => %w(#{options[:include].join(' ')}))
end
def find_all_#{plural_name}
@#{plural_name} = #{class_name}.find :all,
:order => "#{options[:order]}",
:conditions => "#{options[:conditions]}",
:include => %w(#{options[:include].join(' ')})
@#{plural_name} = #{class_name}.find(
:all,
:order => "#{options[:order]}",
:conditions => "#{options[:conditions]}",
:include => %w(#{options[:include].join(' ')})
)
end
def paginate_all_#{plural_name}
@#{plural_name} = #{class_name}.paginate :page => params[:page],
:order => "#{options[:order]}",
:conditions => "#{options[:conditions]}",
:include => %w(#{options[:include].join(' ')})
@#{plural_name} = #{class_name}.paginate(
:page => params[:page],
:order => "#{options[:order]}",
:conditions => "#{options[:conditions]}",
:include => %w(#{options[:include].join(' ')})
)
end
def search_all_#{plural_name}
@#{plural_name} = #{class_name}.find_with_index params[:search],
:order => "#{options[:order]}",
:conditions => "#{options[:search_conditions]}",
:include => %w(#{options[:include].join(' ')})
@#{plural_name} = #{class_name}.with_query(params[:search]).find(
:all,
:order => "#{options[:order]}",
:conditions => "#{options[:search_conditions]}",
:include => %w(#{options[:include].join(' ')})
)
end
def search_and_paginate_all_#{plural_name}
@#{plural_name} = #{class_name}.paginate_search params[:search],
:page => params[:page],
:order => "#{options[:order]}",
:conditions => "#{options[:search_conditions]}",
:include => %w(#{options[:include].join(' ')})
@#{plural_name} = #{class_name}.with_query(params[:search]).paginate(
:page => params[:page],
:order => "#{options[:order]}",
:conditions => "#{options[:search_conditions]}",
:include => %w(#{options[:include].join(' ')})
)
end
protected :find_#{singular_name}, :find_all_#{plural_name}, :paginate_all_#{plural_name}, :search_all_#{plural_name}, :search_and_paginate_all_#{plural_name}
protected :find_#{singular_name},
:find_all_#{plural_name},
:paginate_all_#{plural_name},
:search_all_#{plural_name},
:search_and_paginate_all_#{plural_name}
)

Expand Down Expand Up @@ -211,7 +238,11 @@ def update_positions
end
find_all_#{plural_name}
render :partial => 'sortable_list', :layout => false, :locals => {:continue_reordering => params[:continue_reordering]}
render :partial => 'sortable_list',
:layout => false,
:locals => {
:continue_reordering => params[:continue_reordering]
}
end
# takes in a single branch and saves the nodes inside it
Expand All @@ -220,7 +251,9 @@ def parse_branch(position, id_hash, parent_id)
parse_branch(pos, id, id_hash["id"]) unless pos == "id"
end if id_hash.include?('0')
#{class_name}.update(id_hash["id"], :parent_id => parent_id, :position => position)
#{class_name}.update(id_hash["id"],
:parent_id => parent_id,
:position => position)
end
protected :parse_branch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,9 @@ def create

def index
if searching?
@resources = Resource.paginate_search params[:search],
:page => params[:page],
:order => "created_at DESC"
search_and_paginate_all_resources
else
@resources = Resource.paginate :page => params[:page],
:order => "created_at DESC"
paginate_all_resources
end

if RefinerySetting.find_or_set(:group_resources_by_date_uploaded, true)
Expand Down

0 comments on commit 55be5ee

Please sign in to comment.