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

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)