I want to control when to refresh page (respond_to format.html) and when to toggle buttons (respond_to format.js), by passing local variable to partial used for remote: true (re
@remote_flag
is an instance variable, not the local variable, so it isn't passed to the partial with locals: { user_event: user_event, remote_flag: false }
construction. Since it isn't set, it is (by default) nil
and it behaves like false
in conditional statements. Instead, you should rather use your passed local variable, remote_flag
:
<%= form_for(current_user.favorites.find_by_followed_event_id(user_event),
html: { id: "event_number_#{user_event.id}", method: :delete }, remote: remote_flag) do |f| %>
<%= f.submit "Remove from favorites %>
<% end %>
and pass variable through locals: {...}
construction or set an instance variable explicitly in controller:
@remote_flag = !!condition