<% if @property.for_sale? %>
<%= @property.price > 0 ? number_to_currency(@property.price, precision: 0) : "For Sale" %>
<% else %>
<%= @property.price > 0 ? number_to_currency(@property.price, precision: 0) : "For Rent" %> / month
<% end %>
for_sale variable is set to false
Parameters: { "for_sale"=>"false", "id"=>"3"}
This is the code that sets it to false:
<%= form.select :for_sale, options_for_select({ "Yes" => true, "No" => false }
Therefore the else statement should run. However, this is not reflected on the view side. What am I missing here?
edit 1
"for_sale" variable is set to true by default.
t.boolean "for_sale", default: true
However, when I change it to false with the options_for_select code shown above it still remains as true.
Any clue why?
edit 2
Solved it! for_sale variable was not included in property_params
def property_params
params.require(:property).permit(:name, :address, :price, :rooms, :bathrooms, :parking_spaces,:details, :photo, :photo_cache, :for_sale)
end
falseto make sure that you receive it as boolean?"false"would run a truthiness check, and for that case simply by being a string, it'll take the true "path" of your if condition. In that case, check just if@property.for_sale?== 'false' (or 'true').trueandfalse, it is all just text.options_for_selectis creating something like this<option value="true">Yes</option>, and itsvalue` will be interpreted in Ruby as a string. Similar can be said for numbers (eg.value="1")