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