添加后期提交到 Rails 应用程序?
我在我的 Rails 应用程序中使用以下 gem:
http://github.com/fnando/post_commit
我正在尝试学习如何在应用程序中创建记录时将数据发送到服务提供商(例如 Campfire)。
使用 Campfire 作为测试,我的 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>
有人能指出我在右边吗请问方向?
谢谢,
丹尼
I am using the following gem in my rails application:
http://github.com/fnando/post_commit
I am trying to learn how to send data to service providers such as Campfire on creation of a record in my application.
Using Campfire as a test I have the following in my kase.rb model:
# Campfire
post_commit :campfire do
authorize :subdomain => "XXXXXXXXXX", :token => "XXXXXXXXXXXX", :room => 'XXXXXXX'
post "New Record", :type => :text
end
the following in my 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
and the following in my view:
<%= check_box_tag :send_to_campfire, 1, true %> Send Case to Campfire?
When using the code above, I get an error of:
NoMethodError in KasesController#create
undefined method `post_commit' for #<Class:0x10528e3e8>
Could someone point me in the right direction, please?
Thanks,
Danny
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能需要在使用前明确
require
post_commit
,或者更好的是,确保您的environment.rb
中有以下内容>Rails::Initializer.run 块You may need to explicitly
require
thepost_commit
before use or, better still, make sure you have the following inenvironment.rb
in yourRails::Initializer.run
block