title: Get ID of submitted record after save in AngularJS Rails
body: <p>Basically, here's my controller:</p>
  
  <pre><code>class Api::ProjectsController &lt; ApplicationController
    before_action :set_params, only: [:show]
  
    respond_to :json
  
  
    def new
      @project = Project.new
      render layout: false
    end
  
    def create
      @project = Project.new allowed_params
      @project.sample = false
      @project.users &lt;&lt; current_user
  
      if @project.save
        @project.members &lt;&lt; current_user
        # redirect_to project_path(@project)
  
      else
      end
  
      render json: {new_project: @project}
  
    end
  
      def set_params
        @page   = params[:page]
        @client = params[:client]
        @block  = params[:block]
        @block  = Block.find @block if @block
      end
  
      def allowed_params
        params.require(:project).permit :name, :sample
      end 
  end
  </code></pre>
  
  <p>This is my html snippet:</p>
  
  <pre><code>&lt;form ng-submit='createStream()'&gt;
     &lt;input autofocus='autofocus' class='form-control' id='project_name' placeholder='Untitled Stream' required='required' type='text', ng-model='newProject.name'&gt;
     &lt;br/&gt;
     &lt;input type='submit' value='Create' class='btn btn-md btn-success'&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>My popovercontroller.js.coffee</p>
  
  <pre><code>App.controller("PopoverCtrl", ($scope, Project, $location, $http) -&gt;
      $scope.initializeProject = -&gt;
          $scope.newProject = new Project();
      $scope.createStream = -&gt;
          project = Project.save($scope.newProject)
          $scope.projects.push(project)
  )
  </code></pre>
  
  <p>And the services/factory</p>
  
  <pre><code>App.factory 'Project', ($resource) -&gt;
    $resource "/api/projects/:id", {id: @id},
      query:
        method: "POST"
        isArray: false
  </code></pre>
  
  <p>I can save data into my DB, but I want to redirect to the show view after saving the data.</p>
  
  <p>Just like the default scaffolding for RAILS, wherein after submitting the form given that it is valid... it will redirect to its show page . (e.g. <code>localhost:3000/projects/1</code> with its ID.</p>
  
  <p>However, the behavior now is that after submitting the form, it's not redirecting to the show page. I'm trying to get the ID of the saved record but no luck.</p>
  
  <p>I tried putting <code>$location.path('/projects/' + @id)</code> but seems like <code>@id</code> is undefined and not being recognized. I'm new in manipulating JSON using Angular.</p>
  
  <p><strong>EDIT:</strong> Here's my console logs. I think JSON isn't returning? It redirects to the page where I came from. My form is in popover style so no redirection has been made.</p>
  
  <pre><code>Started POST "/api/projects" for 127.0.0.1 at 2014-01-30 06:38:30 +0800
  Processing by Api::ProjectsController#create as HTML
    Parameters: {"name"=&gt;"XXX", "project"=&gt;{"name"=&gt;"XXX"}}
    User Load (2.5ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 14 ORDER BY `users`.`id` ASC LIMIT 1
     (0.2ms)  BEGIN
    SQL (0.3ms)  INSERT INTO `projects` (`created_at`, `name`, `updated_at`) VALUES ('2014-01-29 22:38:30', 'XXX', '2014-01-29 22:38:30')
     (0.2ms)  INSERT INTO `projects_users` (`project_id`, `user_id`) VALUES (91, 14)
     (16.4ms)  COMMIT
     (0.2ms)  BEGIN
    SQL (0.3ms)  INSERT INTO `project_memberships` (`member_id`, `project_id`) VALUES (14, 91)
     (1.2ms)  COMMIT
  Completed 200 OK in 53ms (Views: 0.5ms | ActiveRecord: 22.3ms)
  
  
  Started GET "/projects/23" for 127.0.0.1 at 2014-01-30 06:38:30 +0800
  
  
  Started GET "/?goto=projects/23" for 127.0.0.1 at 2014-01-30 06:38:30 +0800
  Processing by MainController#index as HTML
    Parameters: {"goto"=&gt;"projects/23"}
    User Load (0.4ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 14 ORDER BY `users`.`id` ASC LIMIT 1
    Rendered main/index.html.haml within layouts/main (0.1ms)
    Rendered application/_header.html.slim (0.5ms)
    Rendered application/_footer.html.slim (0.2ms)
  Completed 200 OK in 40ms (Views: 36.0ms | ActiveRecord: 0.4ms)
  </code></pre>