Q:

Conditional HTML attribute

In ActionView I need to display an attribute based on a condition.
<%= f.text_field :regmax_remote, {
  :class => 'span2', 
  :style => "display:#{@event.regmax_remote.present? ? "block" : "none"};"
} 
%> 

Is there a prettier way to go about this?

A:

The above code is fine, If you are going to use it only once in the,
But If this will be used in many places then u may need helper
def event_display_style event
  event.regmax_remote.present? ? "block" : "none"
end

if you have multiple attributes based on several conditions then u can use the helper to return the attributes in hash format and use it like this.
<%= f.text_field :regmax_remote, event_display_style(@event) %>

if u want a variable hash with default hash then u can do something like this as well
<%= f.text_field :regmax_remote, {class: "span2"}.merge(event_display_style(@event)) %>

There are some other ways to make this code look better. U may also like the draper gem. which gives an object oriented control over displaying at the same time can acce view helpers.
https://github.com/drapergem/draper

