我想在索引页面上生成创建记录而不去其他路线。编辑部分工作成功。当我单击添加记录时,出现 500 错误。它说
undefined method `income_url' for #<Api::IncomesController:0x007fcf1f6407f8>
我在索引页面上使用视图呈现的 create.handlebars 是
<div class="control-group">
<label class="control-label">Income name</label>
<div class="controls">
{{view Ember.TextField valueBinding="newIncomeName"}}
</div>
</div>
<div class="control-group">
<div class="controls">
<input type="submit" value="Add" {{action submit content}}>
</div>
</div>
我的 route.js.coffee 是:
EmberMoney.Router.reopen
location: 'history'
EmberMoney.Router.map ->
@resource 'incomes', ->
@route 'index' # this route is used for creating new records
EmberMoney.IncomesRoute = Ember.Route.extend
model: ->
EmberMoney.Income.find()
EmberMoney.IncomesEditRoute = Ember.Route.extend
setupController: (controller, model) ->
if model.get('transaction') == @get('store').get('defaultTransaction')
transaction = @get('store').transaction()
transaction.add model
controller.set('content', model)
deactivate: ->
@modelFor('incomes.edit').get('transaction').rollback()
events:
submit: (record) ->
record.one 'didUpdateRecord', =>
@transitionTo 'index'
record.get('transaction').commit()
EmberMoney.IncomesIndexRoute = Ember.Route.extend
model: ->
EmberMoney.Income.createRecord()
setupController: (controller, model) ->
controller.set('content', model)
events:
submit: (record) ->
record.on "didCreate", =>
@transitionTo 'index'
record.get('transaction').commit()
我的 api/incomes_controller.rb 是:
class Api::IncomesController < ApplicationController
respond_to :json
def index
respond_with Income.all
end
def show
respond_with Income.find(params[:id])
end
def create
respond_with Income.create(params[:income])
end
def update
respond_with Income.update(params[:id], params[:income])
end
def destroy
respond_with Income.destroy(params[:id])
end
end
非常感谢您的帮助。