ruby on rails - Output integer as phone number format in view -
i trying show show formatted phone number like: xxx-xxx-xxxx
instead of number string ..any great!
<% if @post.phone.present? %> <h4>phone: <small> <%= @post.phone %><br></h4> <% end %>
you can use number_to_phone helper, this:
<% if @post.phone.present? %> <h4>phone: <small> <%= number_to_phone @post.phone %><br></h4> <% end %>
by default, formats phone number xxx-xxx-xxxx :
2.1.1 :009 > number_to_phone(1235551234) => "123-555-1234" 2.1.1 :010 > number_to_phone("1235551234") => "123-555-1234"
Comments
Post a Comment