Trouble showing https modal from http page
Trouble showing https modal from http page
I have a Rails 3.2.21 app, which requires the user to be logged in to do several actions (e.g. following another user).
The issue is I've switched ONLY the login & signup pages to https; the rest of the app is still http (using rack-ssl-enforcer gem to 301 redirect from http -> https on just those two pages, in case it matters). When opening up a modal via Ajax to show login or signup, it's not working. In the Rails logs it says:
WARNING: Can't verify CSRF token authenticity
WARNING: Can't verify CSRF token authenticity
And in Chrome the console says:
Failed to load https://mydomain/signup: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://mydomain' is therefore not allowed access.
Failed to load https://mydomain/signup: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://mydomain' is therefore not allowed access.
The code looks like this. Clicking the link to follow a user runs the following jQuery code:
$.ajax(
type: "GET",
url: "/follow/" + $(this).data("follow-id")
)
$.ajax(
type: "GET",
url: "/follow/" + $(this).data("follow-id")
)
The FollowsController
has before_filter :login_required
, and the login_required
method in ApplicationController
looks like this:
FollowsController
before_filter :login_required
login_required
ApplicationController
def login_required
redirect_to "/signup" and return
end
def login_required
redirect_to "/signup" and return
end
Without the login & signup pages being https, everything works as normal. When I switched them to https, this problem crept up.
EDIT:
Already tried the solution posted here, to no avail.
1 Answer
1
rack-cors gem to the rescue. That did the trick.
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy