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 г., 15:55:04 UTC+3 пользователь Ruby-Forum.com
User написал:
>
> Had this working until I refactored by putting into a hash and checking
> for blank. Now I get the error: undefined method `key?' for
> nil:NilClass.
>
> I'm still kind of new at this and would appreciate suggestions on what I
> am missing...
>
>
> 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
> self.key != blank
> end
> end
>
>
> Thanks,
>
> Dave
>
> --
> Posted via http://www.ruby-forum.com/.
>
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/d985ca7c-23ea-4dc2-9456-0f3e28587210%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.