I do not understand what I'm doing wrong. RoR project (with WebSocketRails), haml, angular and coffeescript layout. Angular does not save data.

Here is a fragment of the page (haml):

.form-group .col-xs-12 %label.control-label Имя: .col-xs-12 %input.form-control{'ng-model' => 'user_profile.first_name'} .form-group .col-xs-12 %label.control-label Фамилия: .col-xs-12 %input.form-control{'ng-model' => 'user_profile.last_name'} .form-group .col-xs-12 %label.control-label skype: .col-xs-12 %input.form-control{'ng-model' => 'user_profile.skype'} .button-group %button.button.btn.btn-cancel{'ng-click' => "cancel()"} Отмена %button.button.btn.btn-save{'ng-click' => 'save_user_profile()'} Сохранить 

In the appropriate controller, the profile saving method is described:

  @personal.controller 'PersonalAccountCtrl', ['$scope', 'Logging', 'SmipeData', ($scope, Logging, SmipeData) -> $scope.save_user_profile = () -> SmipeData.save_user_profile() ] 

Which calls the class method:

  @smipe.factory 'SmipeData', ['$http', '$rootScope', 'Logging', ($http, $rootScope, Logging) -> class SmipeData ... dispatcher = new WebSocketRails(websocket_url) ... save_user_profile: () -> dispatcher.trigger('smipe.edit', {user:user_profile}, save_user_profile_success, save_user_profile_failure) 

Here dispatcher is an instance of the WebSocketRails class (I connected it by setting the "WebSocketRails" gem). The smipe.edit itself is in turn a method in the controller:

  def edit if current_user and message.has_key? :user if current_user.update_profile(message[:user]) @response[:success] = true @response[:user] = UserSerializer.new(current_user, root: false) else @response[:success] = false end end trigger_success @response end 

Then the success callback from the same SmipeData is executed:

  @smipe.factory 'SmipeData', ['$http', '$rootScope', 'Logging', ($http, $rootScope, Logging) -> class SmipeData ... save_user_profile_success = (data) -> if data.success $rootScope.$apply -> user_profile = data.user else console.log "save_user_profile error" 

Actually everything. But the data in the database did not appear. What am I doing wrong?

It seems like this line should save to the database:

  $rootScope.$apply -> user_profile = data.user 

But she does not save.

Who used Angular and WebSocket'y please tell me how to save to the database. Or tell me where to read about angular and websocket.

PS PostgreSQL database, and it is working, the configs are correct, users are created by devis. But I do not understand how to change their data.

  • 6
    Open already the developer tools in your favorite browser - and find out if the data gets to the server or not. After that, half the question will disappear from you - and with what turned out, it will be possible to work. Now this is not a question, but a test for the identification of prophetic abilities. - Pavel Mayorov
  • one
    Try to write more detailed questions. Explain exactly what you see the problem, how to reproduce it, what you want to get as a result, etc. - Nicolas Chabanovsky
  • one
    And the data on the server then go? - fedornabilkin

1 answer 1

The controller calls the update_profile() method described in the User model. Where all data from the message[:user] form is transferred

 if current_user.update_profile(message[:user]) 

So, the update in update_profile() did not pass the data to the database. Thank you all for responding.

PS angular'ovskoe $apply

 $rootScope.$apply -> user_profile = data.user 

It only updates the associated data in the form.