Sharagoz -- wrote:
I think i am just near to resolve it.. Got the logic to it.. I'll tell
you how i am doing it.
-----------
@month_leaves = Array.new
for i in 1..12
month = i
year = Date.today.year
start_date = Date.parse("#{year}-#{month}-01")
end_date = start_date + 1.month
@month_leaves << Leaves.find(:all, :conditions => [ "employee_id
= ? and start_date >= ? and end_date < ?", session[:employee].id,
start_date, end_date ])
------------
Now two confusions:-
1) Am i assigning the value correct to array.. This is correct way ..
Rit .. Also tried with @month_leaves[i] .. But cant get it to the views
page..
2) How can we give the different names in a loop.. I mean i do not want
this @month_leaves alone handle this situations. But it should be like
.. @month_1, @month_2 etc etc ..
>> Hi Champs, I hope this is not a newbie question.:)
> Its not as bad as last time, but you may still get yelled at, especially
> since you're posting on a monday
>
>
> Leave.sum("DAY(end_date) - DAY(start_date) + 1", :group =>
> "MONTH(start_date)", :conditions =>
> ["YEAR(start_date)=?",the_year_you_want])
>
> This query will work, but requires that you handle leaves that begins in
> one month and ends in another by creating one record for each month.
> This could create new problems because that means you can no longer sum
> the number of leaves in a given period by simply counting the number of
> records.
--
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.