2010-08-02 103 views
2

我用我的Rails應用程序下面的寶石:將提交添加到Rails應用程序?

http://github.com/fnando/post_commit 

我想學習如何在我的應用程序發送數據到服務提供商,如篝火上創造的記錄。

使用營火作爲測試在我kase.rb模型我有以下幾點:

# Campfire 
post_commit :campfire do 
authorize :subdomain => "XXXXXXXXXX", :token => "XXXXXXXXXXXX", :room => 'XXXXXXX' 
post "New Record", :type => :text 
end 

在我kases_controller.rb如下:

# POST /kases 
    # POST /kases.xml 
    def create 
    @company = Company.find(params[:kase][:company_id]) 
    @kase = @company.kases.create!(params[:kase]) 

    respond_to do |format| 
     @kase.sendtocampfire if params[:send_to_campfire] 

     #flash[:notice] = 'Record was successfully created.' 
     flash[:notice] = fading_flash_message("Record was successfully created.", 5) 

     format.html { redirect_to(@kase) } 
     format.xml { render :xml => @kase, :status => :created, :location => @kase } 
    end 
    end 

在我看來,以下幾點:

<%= check_box_tag :send_to_campfire, 1, true %> Send Case to Campfire? 

當使用上面的代碼時,我得到一個錯誤:

NoMethodError in KasesController#create 

undefined method `post_commit' for #<Class:0x10528e3e8> 

請問有人能指出我正確的方向嗎?

感謝,

丹尼

回答

1

您可能需要明確requirepost_commit使用前或者更好的是,確保你已經中environment.rb按照您Rails::Initializer.run

config.gem 'post_commit' 
+0

嗨,如果我添加config.gem'post_commit',錯誤將更改爲:KasesController中的NoMethodError#create 未定義的方法'sendtocampfi re'for# dannymcc 2010-08-02 10:55:24

+0

@dannymcc那麼你在'Kase'模型中有一個名爲'sendtocampfire'的方法嗎?這是什麼包裝'post_commit'調用? – bjg 2010-08-02 11:02:14

+0

嗨,下面是我的加瀨型號:#營火 post_commit:篝火做 授權:子域名=> 「dannyweb」:令牌=> 「820d410dc1850659cfa2bb440efa3ae1b106786d」:房間=> '麥克萊蘭&CO' 後「新案例在調查管理器中創建「,:type =>:text end - 我不知道這是否正確?謝謝,丹尼 – dannymcc 2010-08-02 11:03:51