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

Cannot perform update(PUT) action #44

Closed
Bunthoeun opened this issue Mar 13, 2014 · 9 comments
Closed

Cannot perform update(PUT) action #44

Bunthoeun opened this issue Mar 13, 2014 · 9 comments

Comments

@Bunthoeun
Copy link

I'm using Rails API(REST) with rack-cors. I can get record from server, but can't update.

Server Log:

Started OPTIONS "/sections?_dc=1394560533889&page=1&start=0&limit=25" for 127.0.0.1 at 2014-03-12 00:55:33 +0700

Started GET "/sections?_dc=1394560533889&page=1&start=0&limit=25" for 127.0.0.1 at 2014-03-12 00:55:34 +0700
Processing by SectionsController#index as /
Parameters: {"_dc"=>"1394560533889", "page"=>"1", "start"=>"0", "limit"=>"25"}
Section Load (0.5ms) SELECT A.*,B.name AS Page FROM sections AS A LEFT JOIN pages AS B ON A.page_id=B.id
Completed 200 OK in 191ms (Views: 5.9ms | ActiveRecord: 5.0ms)

Started OPTIONS "/sections/3?_dc=1394560545888" for 127.0.0.1 at 2014-03-12 00:55:45 +0700

ActionController::RoutingError (No route matches [OPTIONS] "/sections/3"):
actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call

Any idea will be appreciate

@monfresh
Copy link

@Bunthoeun This is because you need to set up routes that respond to the OPTIONS method. As you can see in the server log, it says::

ActionController::RoutingError (No route matches [OPTIONS] "/sections/3"):

Any time you see that kind of error, it means something is missing or is not set up correctly in your config/routes.rb file. Unfortunately, the fact that you need to set up a route that responds to OPTIONS is not documented in this repo, but I'm working on submitting a pull request that will add that much needed documentation. In the meantime, you can see how to do it here.

@dmur
Copy link

dmur commented Jul 16, 2014

@monfresh good idea on documenting that, I ran into that as well and some documentation would have helped

@monfresh
Copy link

I will work on the documentation in the next few days.

@timruffles
Copy link
Contributor

Is it not a good idea to deal with the OPTIONs in rack-cors? Seems like an incomplete implementation if you need to add OPTION routes everywhere.

@cyu
Copy link
Owner

cyu commented Sep 7, 2014

Sorry - I just took a quick look at this. Rack::Cors is handling this correctly. For OPTIONS requests, it's looking for a Access-Control-Allow-Methods method as a hint that it is a preflight request. It'll only pass along the OPTIONS request to the app if that header isn't present. What client are you using to test this?

@fguillen
Copy link

I'm having the same issue here. I am explicitly sending the header Access-Control-Request-Method but still receiving No route matches [OPTIONS] error:

curl --header "Access-Control-Request-Method: PUT" -I -X OPTIONS http://reportsdashboard-v2.domain.com.dev/api/reports/XXX1

@aaronromeo
Copy link

@fguillen

I had a similar issue. My problem was the order of my middleware (mentioned in the README. As a result, I had to update the first line for my config definition, effectively bumping the Rack::Cors insertion to the top of my middleware stack.

    config.middleware.insert 0, Rack::Cors do
      allow do
        origins '*'

        resource '*',
          :headers => :any,
          :expose  => ['access-token', 'expiry', 'token-type', 'uid', 'client'],
          :methods => [:get, :post, :put, :patch, :delete, :options]
      end
    end

Hope this helps you.

@fguillen
Copy link

Thanks @aaronromeo I managed to make my config work, it was my mistake, I had forgotten to include :put in my :methods array :/ .. embarrassing, isn't it? :)

@cyu
Copy link
Owner

cyu commented Jul 15, 2017

I believe this issue has been addressed by #106. Closing.

@cyu cyu closed this as completed Jul 15, 2017
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

7 participants