views:

38

answers:

1

I and trying to build a calendar in ruby on rails.

In ruby-on-rails, monday is considered to be the first day of the week, but i have to set sunday as the first. I intend to change this to properly use the date's built-in methods RoR. Assuming today is sunday, oct 24th. Look the example:

Date.now.beginning_of_week

it prints: 2010-10-18 ;but if i could set sunday as the first of the week, it should print : 2010-10-24

A: 

if you don't want to change the API you can just add six days to the date. I'm not sure why ou want six but that is what you have in your question.

Time.now.beginning_of_week + 6.days

helper.rb

def format_date(time)
   time.now.beginning_of_week + 6.days
end 

view

<%= format_date(Time.now) %>
Sam
this is an example of use. the problem of your solution is that i have to do this every time i want to user beginning_of_week and end_of_week
Thiago Diniz
make a helper then, check the code :)
Sam