EDIT: I moved the time math into the model as a callback. I’m getting this error:
NoMethodError in OutstandingsController#create
undefined method `hours' for nil:NilClass
Is there some gem that I need to include to be able to do the time math? I thought it was included in ActiveSupport..?
class Outstanding < ActiveRecord::Base
belongs_to :user
before_validation(:on => :create) do
self.panic_deadline = Time.now
self.panic_deadline = self.panic_deadline + self.deadline_hours.hours
self.panic_deadline = self.panic_deadline + self.deadline_minutes.minutes
self.active = true
end
end
class OutstandingsController < ApplicationController
def create
@outstanding = Outstanding.new(params[:outstanding])
@user = current_user
@outstanding.user_id=@user.id
respond_to do |format|
if @outstanding.save ...
<%= form_for(@outstanding) do |f| %>
<div class="field">
<%= select_tag :deadline_hours, options_for_select(Array(0..99), 0) %><%= f.label :deadline_hours %>
<%= select_tag :deadline_mins, options_for_select(Array(1..59), 30) %><%= f.label :deadline_mins %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Maybe something like
Make sure that there is either a virtual attribute for deadline_hours / deadline_minutes or it’s in the model schema.