Created
March 28, 2014 12:31
-
-
Save JonMidhir/9831651 to your computer and use it in GitHub Desktop.
Setting time attributes using Chronic to parse human text input.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Shift < ActiveRecord::Base | |
validates :starts_at, presence: true | |
def parsable_start_time | |
starts_at.strftime("%-I.%M%P") if starts_at | |
end | |
def parsable_start_time=(time_string) | |
self.starts_at = Chronic.parse(time_string) | |
end | |
end | |
class ShiftsController < ApplicationController | |
# ... | |
def shift_params | |
params | |
.require(:shift) | |
.permit :parsable_start_time #, ... | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment