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
Post a Comment