2

I use rails-backbone gem and I generated a Backbone model. The model includes paramRoot: attribute. I assume it somehow tells Backbone how to connect to the corresponding Rails model, but I can't find any documentation about it.

What does paramRoot actually do?

mu is too short
  • 426,620
  • 70
  • 833
  • 800
Jeewes
  • 1,333
  • 2
  • 16
  • 18
  • Not quite duplicate but the answers might help: http://stackoverflow.com/q/8016296/479863 – mu is too short Nov 12 '12 at 18:22
  • Actually I read that already, but the answer is quite obscure. I issued a new guestion because, that didn't focus directly into this guestion. – Jeewes Nov 12 '12 at 18:27

1 Answers1

12

Backbone-rails doesn't document paramRoot. I suppose you're supposed to use the generators to build your models:

class <%= model_namespace %> extends Backbone.Model
  paramRoot: '<%= singular_table_name %>'
  #...

and blindly do as you're told.

If you want to know what it does then you have to read the source (as usual). The only thing in Backbone-rails that uses paramRoot is their replacement for the standard Backbone.sync; their replacement contains this:

if(model.paramRoot) {
  data[model.paramRoot] = model.toJSON();
} else {
  data = model.toJSON();
}

All that does is change a model's serialized attributes from the standard {attr1: v1, attr2: v2, ...} Backbone form to the { model_name: { attr1: v1, ... } } form that Rails wants; then you can look at params[:model_name] in your Rails controllers rather than looking at just params.

mu is too short
  • 426,620
  • 70
  • 833
  • 800
  • 1
    A better solution might be to use [ActionController::ParamsWrapper](http://api.rubyonrails.org/classes/ActionController/ParamsWrapper.html). – maletor Jun 18 '13 at 20:11
  • @Maletor: That seems like a bit of hack to me (a different hack than the above hacks though :). Seems to be aimed at APIs that are in transition or backwards compatibility issues but I could be wrong about the intent. ParamsWrapper is worth mentioning though. – mu is too short Jun 18 '13 at 20:53