Check for dash before applying titleize in Rails -



Check for dash before applying titleize in Rails -

i new ruby , rails , need know how check if string contains dash before applying titlelize.

@city = city.first :conditions => { :title => params[:city].titleize }

what need is:

@city = city.first :conditions => { :title => params[:city] }

and write apply titleize if @city variable doesn't contain dash.

i solution added zachrose couple of weeks ago: https://gist.github.com/varyonic/ccda540c417a6bd49aec

def nice_title(phrase) homecoming phrase if phrase =~ /^-+$/ phrase.split('-').map { |part| if part.chars.count == part.bytes.count part.titleize else part.split(' ').map { |word| word.mb_chars.titleize }.join(' ') end }.join('-') end

ruby-on-rails-3

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -