I have a weird problem in some JavaScript code that’s a part of one of my RoR projects. Here’s the code:
alert(<%= params[:browse_view]%>)
<% if params[:browse_view] == true %>
alert('Changing to browse view...')
changeToBrowseView();
<% else %>
alert('Changing to list view...')
changeToListView();
<% end %>
What’s happening is that the alert at the top will show false, but then the top portion of the if statement will run. This is going to be a remarkably stupid issue, but I have no idea what’s going on…
Are you sure
params[:browse_view]is abooleanrather than a string?I would take a look at the proven ways to parse string values to their corresponding boolean values:
Parse a String to a Boolean in Ruby on Rails