2013-03-21 23 views
2

我想在索引页上生成创建记录而不转到其他路由。编辑部分成功运行。当我点击添加记录时,我有500错误。它说在Ember的索引页上创建记录js

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 

谢谢很多的帮助。

+0

请解释什么是不工作的。 – 2013-03-21 19:52:44

+0

我更新了我的问题 – ejiqpep6 2013-03-21 20:31:31

+2

这是一个导轨错误 - 我们需要看到您的导轨控制器知道问题所在。 – zaius 2013-03-21 21:21:07

回答

0

在这种情况下,您需要指定响应者的名称空间。尝试: http://api.rubyonrails.org/classes/ActionDispatch/Routing/PolymorphicRoutes.html

class Api::IncomesController < ApplicationController 
    respond_to :json 

    def index 
     respond_with :api, Income.all 
    end 

    def show 
     respond_with :api, Income.find(params[:id]) 
    end 

    def create 
     respond_with :api, Income.create(params[:income]) 
    end 

    def update 
     respond_with :api, Income.update(params[:id], params[:income]) 
    end 

    def destroy 
     respond_with :api, Income.destroy(params[:id]) 
    end 
end 
相关问题