How to short this view code

user4827489

Hi I have included given code in my view

<% if employee.profile.present? %>
   <%= employee.profile.name %>
<% end %>

Please guide me how to dry this code

Nithin

Two ways I would suggest.

  1. <%= employee.profile.try(:name) %>

  2. <%= employee.profile.name if employee.profile %>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to short this view code

From Dev

How to code a centered short underline?

From Dev

How to make this Block of python code short and efficient

From Dev

how to write the simple short code for parsing

From Dev

How do I segue to a new view controller after a short timeout?

From Dev

How to transfer method call to another thread with some short code?

From Dev

How to generate code with short type names instead of full type names?

From Dev

How to retrieve the return code of a command in a short-circuit expression

From Dev

In Sublime Text how do you short-cut writing code?

From Dev

How can I tidy up this short javascript code?

From Dev

How to return scandir output inside Wordpress short code?

From Dev

Short Code Regex

From Dev

Big O of this short code

From Dev

Short code mouseenter & mouseleave

From Dev

Big O of this short code

From Dev

How to view Java compiled code

From Dev

How to view Java compiled code

From Dev

How to view assembly code in codeblocks?

From Dev

How to assign a code snippet or macro to a keyboard short cut in Visual Studio Code (VSC)?

From Dev

Short code to test HTTP latency?

From Dev

What is the numberformat code for Short date?

From Dev

Java String to short hash code

From Dev

Short else in php code (Yii)

From Dev

Jquery: Short code for multiple clearTimeout

From Dev

Short script that displays the code itself?

From Dev

Cyclone Slider short code not working

From Dev

C short writing way of code

From Dev

many same code for button (Short Then)

From Java

How to convert short[] into List<Short> in Java with streams?