[Rails] Re: before_validate refactor question

2013-09-04 Thread Dave Castellano
Michael Aleksandrovich wrote in post #1120644: > Instance of Question doesn't have attribute "key". > If this is ActiveRecord, you maybe should make migration "add_column > :questions, :key, :string", OR within class scope write "attr_accessor > :key" > > , 4 2013 ., 15:17:47 UTC+3 Ruby-Forum.com

[Rails] Re: before_validate refactor question

2013-09-04 Thread Michael Lutsiuk
Instance of Question doesn't have attribute "key". If this is ActiveRecord, you maybe should make migration "add_column :questions, :key, :string", OR within class scope write "attr_accessor :key" среда, 4 сентября 2013 г., 15:17:47 UTC+3 пользователь Ruby-Forum.com User написал: > > But, even t

[Rails] Re: before_validate refactor question

2013-09-04 Thread Dave Castellano
But, even the following causes error: undefined method `key=' for # before_validation :capitalize_first_words def capitalize_first_words [:question, :correct_ans_1, :correct_ans_2].each do|key| self.key = "x" end end key is still not being interpreted as "question

[Rails] Re: before_validate refactor question

2013-09-03 Thread Michael Lutsiuk
before_validation :capitalize_first_words def capitalize_first_words [:question, :correct_ans_1, :correct_ans_2, :correct_ans_3].each do |key| self.key = key.to_s.gsub(/^(\W*?[a-z])/) { |m| m.upcase } if !key.to_s.blank? end end Note the difference betweet

[Rails] Re: before_validate refactor question

2013-09-03 Thread Dave Castellano
Now giving error: undefined method `key' for # In Question model: before_validation :capitalize_first_words def capitalize_first_words [:question, :correct_ans_1, :correct_ans_2, :correct_ans_3].each do |key| self.key = self.key.gsub(/^(\W*?[a-z])/) { |m| m.upcase } if !se

[Rails] Re: before_validate refactor question

2013-09-03 Thread Dave Castellano
Michael Aleksandrovich wrote in post #1120515: > Maybe you mean this? > > before_validation :capitalize_first_words > > def capitalize_first_words > [:question, :correct_ans_1, :correct_ans_2, :correct_ans_3].each > do > |key| > self.key = key.gsub(/^(\W*?[a-z])/) { |m| m.upcase }

[Rails] Re: before_validate refactor question

2013-09-03 Thread Michael Lutsiuk
Maybe you mean this? before_validation :capitalize_first_words def capitalize_first_words [:question, :correct_ans_1, :correct_ans_2, :correct_ans_3].each do |key| self.key = key.gsub(/^(\W*?[a-z])/) { |m| m.upcase } if !key.blank? end end вторник, 3 сентября 2013 г.