title: angularJS + rails 4 / PUT METHOD
body: <p>my POST method works well.
  but my method PUT does not work. I can not find my error..</p>
  
  <p>I have OPTION in the browser...</p>
  
  <pre><code>f {$promise: Object, $resolved: false, $get: function, $save: function, $query: function…}
   app.js:20
  f {id: 1, title: "title updated", content: "Corporis distinctio praesentium est sunt. Est expedita quod. Possimus praesentium est quisquam.", user_id: 0, category_id: 5…}
   app.js:18
  OPTIONS http://195.154.114.102:3000/posts/1.json 404 (Not Found) angular.js:8553
  XMLHttpRequest cannot load http://195.154.114.102:3000/posts/1.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.  
  
  
  
  
  Remote Address:195.154.114.102:3000
  Request URL:http://195.154.114.102:3000/posts.json
  Request Method:OPTIONS
  Status Code:404 Not Found
  Request Headersview source
  Accept:*/*
  Accept-Encoding:gzip,deflate,sdch
  Accept-Language:fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
  Access-Control-Request-Headers:accept, content-type
  Access-Control-Request-Method:PUT
  Cache-Control:max-age=0
  Connection:keep-alive
  Host:195.154.114.102:3000
  Origin:null
  User-Agent:Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36
  Response Headersview source
  Connection:Keep-Alive
  Content-Length:16692
  Content-Type:text/html; charset=utf-8
  Date:Sun, 24 Aug 2014 07:15:35 GMT
  Server:WEBrick/1.3.1 (Ruby/2.1.2/2014-05-08)
  X-Request-Id:e46b4495-a712-478f-9390-f3db95efd9fe
  X-Runtime:0.106774
  </code></pre>
  
  <p><strong>app.js</strong></p>
  
  <pre><code>var app = angular.module('MonApp', ['ngResource']);
  
  app.controller('PostsCtrl', function($scope, $resource){
  
      var Post = $resource('http://195.154.114.102:3000/posts/:id.json', null, {
          'update': { method: 'PUT', params: {id: "@id"}}
      });
  
      $scope.posts = Post.query();
      $scope.post = Post.get({id: 1}, function() {
          $scope.post.title = "title updated";
          $scope.post.$update();
          console.log($scope.post);
      });
  
          console.log($scope.post);
  
  
  
      /*
          var post = new Post;
          post.title = "second article title";
          post.content = "second article content";
          post.$save();
      */
  
  });
  </code></pre>
  
  <p><strong>cat app/controllers/application_controller.rb</strong></p>
  
  <pre><code>skip_before_filter :protect_from_forgery
  before_filter :set_acces
  
  def set_acces
          headers['Access-Control-Allow-Origin'] = '*'
          headers['Access-Control-Request-Method'] = %w{GET POST OPTIONS}.join(",")
  end
  </code></pre>
  
  <p><strong>cat app/controllers/application_controller.rb</strong> (gem ok)</p>
  
  <pre><code>config.middleware.use Rack::Cors do
    allow do
      origins '*'
      resource '*', :headers =&gt; :any, :methods =&gt; [:get, :post, :options]
    end
  end
  </code></pre>
  
  <p><strong>cat app/controllers/posts_controller.rb</strong></p>
  
  <pre><code>  # PATCH/PUT /posts/1
    # PATCH/PUT /posts/1.json
    def update
      respond_to do |format|
        if @post.update(post_params)
          format.html { redirect_to @post, notice: 'Post was successfully updated.' }
          format.json { render :show, status: :ok, location: @post }
        else
          format.html { render :edit }
          format.json { render json: @post.errors, status: :unprocessable_entity }
        end
      end
    end
  </code></pre>