Rails 批量分配和 Backbone.js
我有一个游戏模型,我想在创建时进行批量分配:
def create
game = Game.new(params[:game])
...
end
但是 Backbone 发送模型属性而不将它们包装在“游戏”参数中,我必须这样做:
def create
game = Game.new(:title=>params[:title], ... )
...
end
我希望我的控制器干净,如何使用 Backbone.js 进行批量分配?
I have a Game model and I want to mass assign on create:
def create
game = Game.new(params[:game])
...
end
But Backbone sends model attributes without wrapping them in 'game' param, and I have to do this:
def create
game = Game.new(:title=>params[:title], ... )
...
end
I want my controller clean, how to use mass assignment with Backbone.js?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自 Backbone 创建者的回答:
http://www.quora.com/How-well -does-backbone-js-work-with-rails
Answer From Backbone creator:
http://www.quora.com/How-well-does-backbone-js-work-with-rails
根据我的理解,这可能会对您有所帮助: https://gist.github.com/719080
(不是我的代码,要点由 @trydionel 提供)。
This might help you from what I understand: https://gist.github.com/719080
(Not my code, gist by @trydionel).