views:

38

answers:

1

Hi Everyone,

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

+1  A: 

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
Hi, if I add config.gem 'post_commit' the error changes to: NoMethodError in KasesController#createundefined method `sendtocampfire' for #<Kase:0x105177dd8>
dannymcc
@dannymcc So do you have a method called `sendtocampfire` in your `Kase` model? Is that what wraps the `post_commit` call?
bjg
dannymcc
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