2

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

John Topley
  • 113,588
  • 46
  • 195
  • 237
dannymcc
  • 3,744
  • 12
  • 52
  • 85

1 Answers1

1

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'
bjg
  • 7,457
  • 1
  • 25
  • 21
  • Hi, if I add config.gem 'post_commit' the error changes to: NoMethodError in KasesController#create undefined method `sendtocampfire' for # – dannymcc Aug 02 '10 at 10:55
  • @dannymcc So do you have a method called `sendtocampfire` in your `Kase` model? Is that what wraps the `post_commit` call? – bjg Aug 02 '10 at 11:02
  • Hi, The following is in my Kase model: # Campfire post_commit :campfire do authorize :subdomain => "dannyweb", :token => "820d410dc1850659cfa2bb440efa3ae1b106786d", :room => 'McClelland & Co' post "New Case created in Survey Manager", :type => :text end -- I don't know if that's correct or not? Thanks, Danny – dannymcc Aug 02 '10 at 11:03
  • Just realised I was missing def sendtocampfire from the kase.rb. Sadly though, after that I don't get any errors but the message isn't sent to Campfire - could be an issue with the room name though... – dannymcc Aug 02 '10 at 11:09