I come from php and am just starting to cut my teeth in ruby and rails.
Is there more efficient or a more ‘ruby’ way of writing the following?
<% if !@user.twitter_url.empty? %>
<a class="twitter" href="<%= @user.twitter_url %>">Twitter</a>
<% end %>
<% if !@user.facebook_url.empty? %>
<a class="facebook" href="<%= @user.facebook_url %>">Facebook</a>
<% end %>
<% if !@user.google_plus_url.empty? %>
<a class="googleplus" href="<%= @user.google_plus_url %>">Google Plus</a>
<% end %>
<% if !@user.linked_in_url.empty? %>
<a class="linkedin" href="<%= @user.google_plus_url %>">Linked In</a>
<% end %>
The best way should be to use some Presenter or maybe a helper method. Anyway using metaprogramming you can do
or
Or even: