New to AngularJS. I have some trouble getting the RESTful thing working between angular and rails. I setup a simple rest service and get the post fine. Binding work etc. But when I $update back .. what gets sent to server is the entire post object. I need to be able to filter this down to just certain attributes. Additionally what gets posted is not wrapped inside of params[:post]
which is the typical rails approach.
See below:
# angular
app.factory "Post", ["$resource", ($resource) ->
$resource "/posts_api/:id", {id: "@id"}, {update: {method: "PUT"}}
]
app.controller "PageEditCtrl", ($scope, Post) ->
$scope.post = Post.get(
id: 32723
, ->
$scope.post.title = $scope.post.title + "!"
$scope.post.$update({id: $scope.post.id})
)
......
# in rails Post.rb class
attr_accessible :title, :body, :user_id
# in rails posts_api_controller.rb
class PostsApiController < ApplicationController
respond_to :json
before_filter :authenticate_user!
# **** HERE'S THE PROBLEM:::: 2 issues with updating
# 1) angular is passing *entire post object* with attributes that are *not in attr_accesible*
# 2) angular is not passing the post in the typical rails fashion params[:post] ..instead just as params
def update
respond_with current_user.posts.update(params[:id], params) # would like to have params[:post] instead here
end
end