Question: I'm using `ng-repeat` to create an index of records within a Rails view, on this index I'm trying to implement a button to update a particular record. The problem is I need to pass the correct id through to the Rails controller. I'm getting an error when I attempt to pass the record id through with `'{{swim_record.id}}!'` , using string interpolation via Angular.

```
<tbody>
  <tr ng-repeat='swim_record in SwimRecords | orderBy:predicate.value:reverse |
  filter:search'>
   <td>
     <a ng-href='/swim_records/{{swim_record.id}}'>
      {{swim_record.last_name}}
     </a>
   </td>
   <td>{{swim_record.first_name}}</td>
   <td class = 'hidden-xs'>{{swim_record.check_in | date:'MM/dd/yyyy @ h:mma'}}</td>
   <th class = 'hidden-xs'>{{swim_record.lmsc}}</td>
   <td>
    <%= bootstrap_form_for Swimmer.find_by_id("{{swim_record.id }}!".to_i) do |f| %>
     <%= f.hidden_field :last_name, value: "Hat" %>
     <%= f.submit 'Check Out', class: "btn btn-danger" %>
    <% end %>
   </td>
  </tr>
</tbody>

```

Any suggestions would be very much appreciated!

Answer: 
Promises don't change the language, it's just a library. It cannot change how function returning works. However, do you want something like this:

```
return con.getConnectionAsync().then(function(connection) {
    var x;
    var y;
    return connection.queryAsync('SELECT password,id FROM player WHERE name='+mysql.escape(req.body.user))
        .spread(function(rows, fields) {
        if (hash.verify(req.body.pass,rows[0].password)) {
            req.session.loggedIn = true;
            req.session.user = rows[0].id;
            ref = new P(rows[0].id,x,y);
            res.send({
                "msg":"You have logged in!",
                "flag":false,
                "title":": Logged In"
            });
            return Promise.all([
                getX(rows[0].id,con,mysql),
                getY(rows[0].id,con,mysql)
            ]).then(function(xy) {
                x = xy[0];
                y = xy[1];
            }).return(ref);
        } else {
            // Should probably throw a LoginError here or something
            // because if we get here, we don't define x and y
            // and that will require an annoying check later
            res.send({
                "msg":"Your username and or password was incorrect.",
                "flag":true,
                "title":": Login Failed"
            });
        }
    }).then(function() {
        // If the login succeeded x and y are defined here.
        // However, in the else branch you don't define
        // x and y so you will need to check here.
        // Had you thrown an error in the else branch
        // you would know that x and y are always defined here.
        use(x, y);
    }).finally(function() {
        connection.release();
    });
});

```
The functions `getX` and `getY` are asynchronous functions. Promise solves the issue of nesting anonymous functions, but it don't make the functions synchronous and blocking.

So `x` and `y` are not set at the moment you create the `ref` object and return this object.

Try something like this:

```
getX(rows[0].id,con,mysql).then(function(data) {
    x = data; //x logs the return 7 from the db
    getY(rows[0].id,con,mysql).then(function(data) {
        y = data; //y logs 45 from the db
        console.log(x,y,"line77"); //logs "undefined undefined line77"
        ref = new P(rows[0].id,x,y);
    });
});

```

Also because your whole function is asynchronous, you have to work with an callback or return a promise, in which you have access to `ref` Object.