checkbox - rails check_box_tag disapear -


i want make form based on check_boxes, , want checked, if '@clans' array not nil , contains 'value' of given checkbox.

my first atemnpt was:

<%= check_box_tag 'clans[]','feniks', true if !@clans.nil? , @clans.include? 'feniks' %> 

but when @clans nil, check_box disappears, disabled.

i managed solve code that:

  <% if !@clans.nil? , @clans.include? 'feniks' %>     feniks: <%= check_box_tag 'clans[]','feniks', true %>   <% else %>     feniks: <%= check_box_tag 'clans[]','feniks' %>   <% end %> 

but looks bad, there have better way write :)

please show me how handle :)

wrap if logic inside parenthesis.

<%= check_box_tag 'clans[]','feniks', (true if !@clans.nil? , @clans.include? 'feniks') %> 

in code, if working modifier. print 10 if x.present?. in sample, if x not blank, method call print(10) happened, otherwise not. same analogy holds case also. inside erb tag, code being interpreted :

<%= check_box_tag('clans[]','feniks', true) if <condition> %> 

that's why when condition true, check_box_tag method getting invoked otherwise not. write whole if part :

<%= check_box_tag 'clans[]','feniks', @clans.try(:include?, 'feniks') %> 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -