I have the following in my controller:
if params[:archive] == 'true'
@archived_new_status = true
else
@archived_new_status = false
end
Then later in create.je.erb do:
<% if !@archived_new_status.nil? %>
xxx.myfuncthatNeedsTrueOrFalse(<%=@archived_new_status%>);
<% end %>
That only works when @archived_new_status is true, when it's false that seems to not be getting set as false. When I do a Rails.logger.info on @archived_new_status for false it outputs nothing, if I inspect it, I get false.
Any thoughts?
The code in the controller can be written:
@archive_new_status = (params[:archive] == 'true')
View: I don't understand why you check if the variable is nil; @archive_new_status is either true or false, so simply call the JS code (using to_json for any argument you have):
xxx.myfuncthatNeedsTrueOrFalse(<%= @archived_new_status.to_json %>);
try:
<% if !@archived_new_status.blank? %>
xxx.myfuncthatNeedsTrueOrFalse(<%=@archived_new_status%>);
<% end %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With