0
votes

I'm not sure if this behavior is normal or not, but when I do:

render js: "window.location.pathname = '#{new_user_session_path}';"

in my controller, it briefly displays the text window.location.pathname = '/user/sign_in'; before executing the line and redirecting successfully.

Here's the full controller action:

def vote_down
    if user_signed_in?
      current_user.vote_exclusively_against(@deal = Deal.find(params[:id]))

      render :partial => 'deals/partials/interaction', 
        :locals => {:deal => @deal, :votes_for => @deal.votes_for, :votes_against => @deal.votes_against}
    else
      render js: "window.location.pathname = '#{new_user_session_path}';"
      flash[:error] = 'Please sign in to vote.'
    end
  end

How do I prevent this from happening and directly render that template?

1

1 Answers

1
votes

Why not just use the rails controller routing to redirect back to new_user_session_path?

respond_to do |format|
   format.html { redirect_to new_user_session_path, error: 'Please sign in to vote.' }
end