saya agak bingung kenapa musti jadi ribet gitu ya? kalo pengalaman-saya
sih buat search nggak perlu bikin hash2 kayak gitu.
controller
def index
@search = Student.new
end
def search
@result = Student.find(:conditions => "field1 like ?")
end
dan seterusnya (conditions-nya di lengkapin gitu)
atau sekarang dah ada metode yg lebih canggih? harap maklum masih di
rails 1, instant rails 1.7 :D
On 10/19/2009 11:20 AM, Bobby Adi Prabowo wrote:
>
> ok makasih bgt.
>
> On Oct 19, 2009, at 10:34 AM, Arie Kusuma Atmaja wrote:
>
> > 2009/10/19 Bobby Adi Prabowo <[email protected]
> <mailto:tigaenamb%40gmail.com>>:
> >
> > > akhirnya saya ubah jadi seperti ini
> > >
> > > def index
> > >
> > > hash = params[:search]
> > >
> > > if !hash.nil?
> > > if !hash["date_birth_equals(1i)"].blank? && !hash
> > > ["date_birth_equals(2i)"].blank? && !hash["date_birth_equals
> > > (3i)"].blank?
> > > hash["date_birth_equals"] = hash["date_birth_equals(1i)"] +
> > > "-" + hash["date_birth_equals(2i)"] + "-" + hash["date_birth_equals
> > > (3i)"]
> > >
> > > end
> > >
> > > if !hash["register_date_equals(1i)"].blank? && !hash
> > > ["register_date_equals(2i)"].blank? && !hash["register_date_equals
> > > (3i)"].blank?
> > > hash["register_date_equals"] = hash["register_date_equals
> > > (1i)"] + "-" + hash["register_date_equals(2i)"] + "-" + hash
> > > ["register_date_equals(3i)"]
> > >
> > > end
> > > hash.delete("date_birth_equals(1i)")
> > > hash.delete("date_birth_equals(2i)")
> > > hash.delete("date_birth_equals(3i)")
> > > hash.delete("register_date_equals(1i)")
> > > hash.delete("register_date_equals(2i)")
> > > hash.delete("register_date_equals(3i)")
> > > end
> > >
> > > @search = Student.search hash
> > > @students = @search.paginate :page => params[:page], :per_page
> > =>
> > > 10, :order => 'id DESC'
> >
> > Pindahkan semua proses ini ke Model student.rb dan Anda seharusnya
> > bisa mulai me-refactor codes Anda di model Anda setelah itu. Jadi
> > kalau sudah bersih seharusnya codes Anda di controller tinggal :
> >
> > @students = Student.bobkeren_search(your_hash_parameters)
> >
> > > ada yang punya ide lebih baik?
> >
> > May The Force be with you. http://bit.ly/Oue4s <http://bit.ly/Oue4s>
> >
>
> [Non-text portions of this message have been removed]
>
>
[Non-text portions of this message have been removed]