0

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 @params.id (error, user) =>
    user.updateAttributes @params.user, (error) =>
      if error
        @render "edit", locals: user: user
      else
        @render "show", locals: user: user 

Console shows me that id parameters is passed:

Parameters:
{ user: 
  { name: 'admin',
    email: 'example@domain.com',
    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.

Marcin Rogacki
  • 501
  • 6
  • 23

1 Answers1

1

This code:

f @params.id (a, b) => ...

is equivalent to this:

f(@params.id((a,b) => ...))

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

update: ->
  App.User.find @params.id, (error, user) =>
    #---------------------^
mu is too short
  • 426,620
  • 70
  • 833
  • 800