添加后期提交到 Rails 应用程序?

发布于 2024-09-12 09:56:59 字数 1324 浏览 8 评论 0原文

我在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

纵情客 2024-09-19 09:56:59

您可能需要在使用前明确require post_commit,或者更好的是,确保您的 environment.rb 中有以下内容>Rails::Initializer.run 块

config.gem 'post_commit'

You may need to explicitly require the post_commit before use or, better still, make sure you have the following in environment.rb in your Rails::Initializer.run block

config.gem 'post_commit'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文