AngularJS的新功能。在角度和轨道之间运行RESTful的东西时遇到了一些麻烦。我设置了一个简单的休息服务,并获得罚款。绑定工作等等。但是,当我更新回来..发送到服务器的是整个post对象。我需要能够将其过滤到某些属性。此外,张贴的内容不包含在params[:post]
这是典型的导轨方法。AngularJS和Rails休息设置
见下文:
# 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
不知道这是否会帮助你,但有一个很好的投射角js轨道。 http://railscasts.com/episodes/405-angularjs虽然这一集是“专业”,所以要得到它,你必须注册(9美元月) – cgat 2013-03-02 02:56:58