Skip to content

Instantly share code, notes, and snippets.

@tmarkiewicz
Created July 25, 2012 19:43
Show Gist options
  • Save tmarkiewicz/3178156 to your computer and use it in GitHub Desktop.
Save tmarkiewicz/3178156 to your computer and use it in GitHub Desktop.
Example of using StatsMix in a Rails controller
class PostsController < ApplicationController
# POST /posts
# POST /posts.json
def create
@post = Post.new(params[:post])
respond_to do |format|
if @post.save
# send a value of 1 to the 'Posts Created' metric with a timestamp of now
StatsMix.track('Posts Created', 1)
format.html { redirect_to @post, :notice => 'Post was successfully created.' }
format.json { render :json => @post, :status => :created, :location => @post }
else
format.html { render :action => "new" }
format.json { render :json => @post.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /posts/1
# DELETE /posts/1.json
def destroy
@post = Post.find(params[:id])
@post.destroy
StatsMix.track('Deleted Posts', 1)
respond_to do |format|
format.html { redirect_to posts_url }
format.json { head :no_content }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment