2015-06-29 54 views
0

我在另一個追索權「預算」內部有一個稱爲「交易」的嵌套追索權。Rails 4 LocalJumpError爲嵌套的追索權形式

我所要做的就是讓我的用戶能夠編輯個人「交易」。然而,當我去/ 1 /交易/ 1 /編輯時,我得到一個LocalJumpError說「沒有塊給(yield)」。 可能有一個非常簡單的解決方案,但我還沒有找到它。

的routes.rb

resources :budgets, :path => '/' do 
    resources :transactions 
end 

budget.rb:

class Budget < ActiveRecord::Base 
    belongs_to :user 
    has_many :transactions 

    validates :amount, presence: true 
    validates :title, presence: true 
    validates :user, presence: true 
    validates :amount, numericality: true 

    extend FriendlyId 
    friendly_id :title, use: :slugged 

    def should_generate_new_friendly_id? 
    new_record? 
    end 
end 

transaction.rb

class Transaction < ActiveRecord::Base 
    belongs_to :user 
    belongs_to :budget 

    validates :amount, presence: true 
    validates :user, presence: true 
    validates :budget, presence: true 
    validates :date, presence: true 
    validates :amount, numericality: true 
    validates :is_positive, :inclusion => {:in => [true, false]} 
end 

transactions_controller.rb

def edit 
    @budget = Budget.friendly.find(params[:budget_id]) 
    @transaction = @budget.transaction 
    end 

並在視圖交易/ edit.html.erb

<%= form_for(@transaction) do |f| %> 

我缺少什麼?

回答