Is there a better way of writing this? Is it possible to do cleanly in one line?
conditions = ["category = ?", params[:category]] if params[:category]
@events = CalendarEvent.all( :conditions => conditions )
Is there a better way of writing this? Is it possible to do cleanly in one line?
conditions = ["category = ?", params[:category]] if params[:category]
@events = CalendarEvent.all( :conditions => conditions )
Not really too much to consolidate but you don't have a lot going on so shouldn't matter.
def action
options = {:conditions => ['category=?', params[:category]]} if params[:category]
@events = CalendarEvent.find(:all, options)
end
@events = CalendarEvent.all(
:conditions => (params[:category] ? ["category = ?", params[:category]] : nil))