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

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -