目前,如果用户没有登录,当用户按下按钮时,它会正确显示警报,然后继续实际提交。我希望它显示警报但然后停留在当前页面(即不直接到提交页面)。我怎样才能做到这一点?
<% if current_user %>
<div class="form-actions">
<%= f.button :submit, :class => "btn btn-info btn-large" %>
</div>
<% else %>
<%= f.button :submit, :class => "btn btn-info btn-large", :onclick => 'alert("You need to be logged in to add comments!")'%>
<% end %>