Rails 3: Create an "empty" ActiveRecord query object -


is possible in rails, create "empty" activerecord query object given model? empty means me condition, includes possible rows in db. want apply filters query afterwards.

at moment using booking.where('id > ?', 0), believe there has nicer way booking.all() - all() returns array , not activerecord. here´s code:

@bookings = booking.where('id > ?', 0) if !@day.nil?     @bookings = @bookings.where('day = ?',@day) end if @project_id && !@project_id.empty?     @bookings = @bookings.where('project_id = ?', @project_id) end 

thanks help!

you can use scoped method discussed here: http://guides.rubyonrails.org/active_record_querying.html#working-with-scopes

also note @project_id.present? same @project_id && !@project_id.empty?


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -