Raony Vieira ferreira wrote:
> CONTROLLER
>
> def index
> @contract = Contract.new(params[:contract])
> page = (params[:page] ||= 1).to_i
> @contracts = Contract.search_index({:page => page})
> @legal_entities = LegalEntity.all(:select => "CD_PESSOA_JURIDICA,
> NM_PESSOA", :joins => [:person])
> @persons = Person.all
> respond_to do |format|
> format.html # index.html.erb
> end
> end
>
>
> def list
> @contract = Contract.new(params[:contract])
> page = (params[:page] ||= 1).to_i
> @contracts = Contract.find_by_params(params[:contract])
> @legal_entities = LegalEntity.all(:select => "CD_PESSOA_JURIDICA,
> NM_PESSOA", :joins => [:person])
> @person = Person.all
> render :index
> end
Seems like this should all be controller work (well, not quite, and this
is based on the mislav-will_paginate gem)...
You could use a generic
@contracts = Contract.paginate :conditions => cond, :page =>
params[:page]
where cond is your scoping criteria, such as:
cond = ['name LIKE ?', some_params_entry] or
cond = ['1=1'] for the everything case
The only difference in your two methods is the Contract.find...
Not knowing what the search_index or find_by_params methods do
precisely, could you create a single build_conditions method in the
Contract model that returns 'cond' and covers all your search cases to
simplify your logic?
index and list are awfully similar... do you need both?
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.