css - Using Booleans in Rails to display & hide info - Rails 4 -


i new rails , quite unsure how go below issue, or advise appreciated - thank in advance

  • i have boolean "advertise job without salary"
  • when user ticks box [giving true result] salary of advert not displayed @ show.html.erb page
  • if user not tick box [giving false result] salary of advert displayed @ show.html.erb page

enter image description here

i tried below no success - or advise appreciated:

show.html.erb

<p>   <strong>advertise without salary:</strong>   <%= @advert.salarydisplay %>    <% if @advert.salarydisplay == "true"  %>     <%= "i want advertise without salary" %>     <%= @advert.salarystart class: "hide" %>     <%= @advert.salaryend class: "hide" %>   <% else %>    <%= "i want advertise salary" %>    <%= @advert.salarystart %>    <%= @advert.salaryend %>   <% end %> </p> 

css file

.hide {    display: none;  } 

are using default sqlite chance?

in sqlite have write way since stores boolean "t" , "f" (kind of pain in neck eh, more know!)

<% if @advert.salarydisplay == "t"  %> 

edit max pointed out, use instead:

<% if @advert.salarydisplay? %> 

also, consider refactoring , adding logic helper or decorator, ideally in view want little no logic :)


Comments