admin管理员组文章数量:1277899
I'm using rails and learning Backbone.
Help me please. Is there any way to set right model on save? When I create, for example, new user with some params and trying save it into the database, - on server side I have not user as object, but user fields in params. And only way to save user - is to set properties manually:
user = User.new(:login => params[:login], :password => params[:password]).save!
Is there any way which will generate real user model object (like a form_for generates)? I think actions described below I will need to use when I will update user and so on.
Thanks!
I'm using rails and learning Backbone.
Help me please. Is there any way to set right model on save? When I create, for example, new user with some params and trying save it into the database, - on server side I have not user as object, but user fields in params. And only way to save user - is to set properties manually:
user = User.new(:login => params[:login], :password => params[:password]).save!
Is there any way which will generate real user model object (like a form_for generates)? I think actions described below I will need to use when I will update user and so on.
Thanks!
Share Improve this question asked Nov 4, 2011 at 22:11 ValeriiVasinValeriiVasin 8,71611 gold badges59 silver badges79 bronze badges2 Answers
Reset to default 10The 'paramRoot' parameter is used by the backbone_rails_sync adapter that backbone-rails gem provides. That's why you can't find it in backbone's website.
Another way, if you are not using the gem and it's adapter, is to render the user with :root => false
render json: @user, root: false
There is a paramRoot 'parameter'. You say rails - so I'll assume coffee script:
class User extends Backbone.Model
paramRoot: 'user'
<url or some other stuff>
本文标签: javascriptBackbone model saveStack Overflow
版权声明:本文标题:javascript - Backbone model save - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741262541a2367886.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论