Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORS headers are being returned for non-CORS OPTIONS requests #58

Open
cyu opened this issue Oct 14, 2014 · 1 comment
Open

CORS headers are being returned for non-CORS OPTIONS requests #58

cyu opened this issue Oct 14, 2014 · 1 comment

Comments

@cyu
Copy link
Owner

cyu commented Oct 14, 2014

This OPTIONS request in this comment should not be returning CORS headers: #20 (comment)

@scervera
Copy link

I was able to fix this issue by only returning headers instead of redirecting. This was accomplished in my Rails API by placing the following code in my create action:

def create
@passage = Passage.new(passage_params)

respond_to do |format|
  if @passage.save
    # formatting this way is required for Angularjs app to not return a http 406 status
    format.html do
      head 200, content_type: "text/plain"
    end
    format.json { render json: @passage.to_json }

    # previous code is commented out in the following 2 lines
    # format.html { redirect_to @passage, notice: 'Passage was successfully created.' }
    # format.json { render :show, status: :created, location: @passage }
  else
    format.html { render :new }
    format.json { render json: @passage.errors, status: :unprocessable_entity }
  end
end

end

See my post here for additional details: http://stackoverflow.com/q/26977623/964018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants