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
But, even the following causes error: undefined method `key=' for
#Question:0x007fcba5972f20
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
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 the
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 User
:
I
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
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 }
if
Now giving error:
undefined method `key' for #Question:0x007fdff26b7798
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 =
7 matches
Mail list logo