html - Can you use if/else statements to style divs in erb? -


sorry if terribly asked; first post on here. using erb ruby on rails , want know if can make background-color of div differ based on user selection. looked online , couldn't find answer. new , still trying learn how search.

            <div class="row">     <% @stores.each |store| %>         <div class="col s12 m6">          <% if store.color = 'red' %>             <% profile_color = 'red' %>         <% elsif store.color = 'blue' %>             <% profile_color = 'blue' %>         <% elsif store.color = 'green' %>             <% profile_color = 'green' %>         <% elsif store.color = 'orange' %>             <% profile_color = 'orange' %>         <% end %>               <div class="card <%= profile_color %> center">                 <div class="card-content white-text">                     <span class="card-title"> <%= store.name %> </span>                     <h6>owner: <%= store.owner %> </h6>                     <h6>location: <%= store.location %> </h6>                 </div>                 <div class="card-action" >                     <%= link_to 'visit store', store_departments_path(store) %>                     <%= link_to 'edit', edit_store_path(store) %>                     <%= link_to 'delete', store_path(store), method: :delete,                          data: {confirm: 'really delete?'} %>                 </div>             </div>         </div>     <% end %> </div> 

i use form asks user color , pic drop down type string. have checked , @store.color storing color , everything.

the problem profile_color defined in scope of each if when reach class attribute nil, see if's aren't doing more assign same value, can change:

<div class="card <%= profile_color %> center"> 

to use store.color like:

<div class="card <%= store.color %> center"> 

and remove if's


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -