Empty virtual attributes --- issue model
Added by Nicola Randestadt over 14 years ago
Hi to all you, I have to modify issues creation/editing by adding the start time (in the database).
Start time (and similarly end time) can be set in the view with a select for hours (0..23) and a select for minutes (0..55): in the database I added a column to the issue table to store start time. Since the new information in the view isn't stored in the database, I defined virtual attributes and set up things so the database column can be set properly. Here's what i've added:
attr_accessor :end_hour, :end_minute, :start_hour, :start_minute before_validation :get_times validate :time_validations #before_save :set_times def time_validations logger.info "Start hour: " + @start_hour.to_s if @start_hour.blank? || @start_minute.blank? errors.add :start_hour, "can't be left blank" end end def get_times logger.info "get_times, ora inizio: #{@start_hour}" @start_time = @start_hour.to_i * 60 + @start_minute.to_i @end_time = @end_hour.to_i * 60 + @end_minute.to_i end
In a test project created from scratch everything worked fine, but in Redmine the instance variables of start_hour.. are nil. Why?
Thank you, greetings
nicola
Replies (1)
[SOLVED] Empty virtual attributes --- issue model - Added by Nicola Randestadt over 14 years ago
Solved.