我有2种型号配方和成分。他们有很多并属于协会。
食谱:Id,标题。成分:id,name,recipe_id
我使用配方和成分创建嵌套表单。我可以在客户端的每个成分中设置recipe_id,但我认为这是个坏主意,因为用户可以破解并更改此ID。
在保存到后端时设置父ID的正确方法是什么?
recipes_new_controller.js.coffee
App.RecipesNewController = Ember.ObjectController.extend
save: ->
console.log "save recipe"
@transaction.commit()
new.emblem
h1 Create recipe
form
div
label{bindAttr for='title.elementId'} Title
Ember.TextField valueBinding='title' name='title' viewName='title'
div
label{bindAttr for='about.elementId'} About
Ember.TextArea valueBinding='about' name='about' viewName='about'
#ingredients
h3 Ingredients
each ingredient in content.ingredients
.control-group
.controls
Ember.TextField valueBinding='ingredient.about'
a{ action removeIngredient ingredient target='controller' } href='#' Remove
div
a{ action addIngredient target='controller' } href='#' Add Ingredient
button.btn.btn-success{ action save this } Create
button.btn.btn-inverse{ action cancel this } Cancel