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
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
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
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
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
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 }
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 г.
7 matches
Mail list logo