Action update in towerjs controller does not work


I'll try create a controler in towerjs, but I have an error while updating action:

TypeError: Property 'id' of object #<Object> is not a function

Here how looks my action:

update: ->
  App.User.find (error, user) =>
    user.updateAttributes @params.user, (error) =>
      if error
        @render "edit", locals: user: user
        @render "show", locals: user: user 

Console shows me that id parameters is passed:

{ user: 
  { name: 'admin',
    email: '',
    password: '21232f297a57a5a743894a0e4a801fc3' },
  id: '4faa6c614b2ce49b34000001',
  action: 'update',
  format: 'html' }

more info: The identical actions are built in show, edit, destroy and they are working. All actions uses the same _form partial.

Problem courtesy of: Marcin Rogacki


This code:

f (a, b) => ...

is equivalent to this:

f(,b) => ...))

so you're trying to call as a function and passing your (error,user) => function to as its argument. I think you want to pass and (error,user) => to App.user.find as two arguments so add a comma:

update: ->
  App.User.find, (error, user) =>
Solution courtesy of: mu is too short


There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.