search for: workdate

Displaying 5 results from an estimated 5 matches for "workdate".

Did you mean: workdata
2013 Mar 04
0
fields_for with accepts_nested_attributes: how to pass a value to a label
...owing object build in the controller: class TimesheetsController < AC ... def new @timesheet = current_user.timesheets.new now = Date.today #generating 7 time entries: monday through sunday (now.beginning_of_week..now.end_of_week).step { |date| @timesheet.time_entries.build(:workdate; date) end end ... In the Timesheet model I defined accepts_nested_attributes for time_entries association: class Timesheet < AR has_many :time_entries, :dependent: :destroy accepts_nested_attributes_for :time_entries, reject_if: proc { |attr| attr[''worktime].blank? } end in...
2013 Mar 30
1
How to use group in nested associations
...:activities, dependent: :destroy, inverse_of: :timesheet has_many :time_entries, through: :activities accepts_nested_attributes_for :activities, allow_destroy: true end class Activity < AR belongs_to :timesheet, inverse_of: :activities belongs_to :task has_many :time_entries, order: :workdate, dependent: :destroy, inverse_of: :activity accepts_nested_attributes_for :time_entries, allow_destroy: true, reject_if: proc { |a| a[:worktime].blank? } end class TimeEntry < AR belongs_to :activity, :inverse_of => :time_entries end How is it possible to group all the time sheets by...
2013 Mar 25
1
validates presence of foreign key fails in nested form
...low_destroy: true end class Activity < ActiveRecord::Base attr_accessible :task_id, :timesheet_id, :time_entries_attributes validates :task_id, presence: true, uniqueness: { scope: ''timesheet_id''} belongs_to :timesheet belongs_to :task has_many :time_entries, order: :workdate, dependent: :destroy accepts_nested_attributes_for :time_entries, allow_destroy: true, reject_if: proc { |a| a[:worktime].blank? } end As you see, I didn''t define any validation for timesheet_id presence in Activity model. It works fine in the browser, but it is still possible to cr...
2013 Mar 26
0
nested forms: use validate :some_method works in update mode only
...: true validates :status, presence: true, inclusion: {in: STATUS_VALUES} validate :maximum_worktime_per_day after_update :check_an_activity_present after_initialize :init_working_week .. private def maximum_worktime_per_day time_entries_by_date = time_entries.group_by(&:workdate) time_entries_by_date.each do |key, value| errors[:base] << "Maximum daily time should not exceed 1 day" if value.map(&:worktime).inject(:+) > 1 break end end As I could see the output in the console, when creating a new record, the hash ...
2013 Mar 04
2
accepts_nested_attributes: undefined method 'association'_attributes
..._id, :time_entries_attributes has_many :time_entries, dependent: :destroy accepts_nested_attributes_for :time_entries, :reject_if => proc { |attributes| attributes[''worktime''].blank? } end class TimeEntry < ActiveRecord::Base attr_accessible :task_id, :timesheet_id, :workdate, :worktime belongs_to :timesheet end As explained in Rails API: ``` Using with attr_accessible The use of attr_accessible can interfere with nested attributes if you’re not careful. For example, if the Member model above was using attr_accessible like this: attr_accessible :name You wou...