Tuesday, September 3, 2013

[Rails] Re: before_validate refactor question

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 !key.blank?
> end
> end
>
> , 3 2013 ., 15:55:04 UTC+3 Ruby-Forum.com
> User :


Thanks!

--
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 rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/49e0fa710d6a925b576c2a0eb4e79a37%40ruby-forum.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment