JZ.
JZ.

Reputation: 21877

ROR - My logic works, Boolean value doesn't post

My logic tests an inventory supply; and the < operator functions fine. How do I assign boolean values to "instock"? (using POST) In this test, under both conditions the value remains unchanged and this sample code does not work.

Also this code is placed in an html.erb file, is there a better place for this code?

 <% if @inventory.needed < @inventory.amount then %>
         <%  @inventory.instock = 'true' %>
        <% else %>
           <% @inventory.instock = 'false' %>
        <% end %>

Thank you in advance for your suggestions!

Upvotes: 0

Views: 229

Answers (1)

bensie
bensie

Reputation: 5403

You are setting instock equal to the string value of "true".

@inventory.instock = true

Is what you want...

Upvotes: 1

Related Questions