1

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 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.