Rails 3 can't get beginning_of_week -


have publish_on datetime field.

just trying begining_of_week publish_on.

tried helper

def start_week(publish_on)   datetime.parse(publish_on).beginning_of_week end 

and in view <%= start_week(@survey.publish_on) %>

tried in model

def set_start_week   publish_on.beginning_of_week end 

hell, tried helper

def this_should_work   datetime.now.beginning_of_week end 

but returns invalid date view. works in irb, why not in view?

edit

module surveyshelper   require 'date'   require 'time'    def this_should_work     datetime.now.beginning_of_week   end end 

take_survey.html.erb

<%= this_should_work %> 

error invalid date

in rails 3.0.9 got

undefined method `at_beginning_of_week' 

wherever put it, alternative solution is:

def somemethodputanywhere ... @datey = date.today @monday = @datey - @datey.wday + 1  #@monday monday of current week. #remove constant '+1' if week begins sunday... ... end 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -