Skip to content

Instantly share code, notes, and snippets.

@jvkumar
Created August 19, 2012 23:05
Show Gist options
  • Save jvkumar/3398416 to your computer and use it in GitHub Desktop.
Save jvkumar/3398416 to your computer and use it in GitHub Desktop.
All info
Model: posts.rb
-----------
class Post
include Mongoid::Document
include Mongoid::Slug
field :name, type: String
field :title, type: String
field :content, type: String
validates :title, :presence => true, :length => { :minimum => 10 }
has_many :comments
slug :name
end
Controller: posts_controller.rb
---------------
class PostsController < ApplicationController
# GET /posts
# GET /posts.json
def index
@posts = Post.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @posts }
end
end
# GET /posts/1
# GET /posts/1.json
def show
@post = Post.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @post }
end
end
# GET /posts/new
# GET /posts/new.json
def new
@post = Post.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @post }
end
end
# GET /posts/1/edit
def edit
@post = Post.find(params[:id])
end
# POST /posts
# POST /posts.json
def create
@post = Post.new(params[:post])
respond_to do |format|
if @post.save
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
# PUT /posts/1
# PUT /posts/1.json
def update
@post = Post.find(params[:id])
respond_to do |format|
if @post.update_attributes(params[:post])
format.html { redirect_to @post, notice: 'Post was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
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
respond_to do |format|
format.html { redirect_to posts_url }
format.json { head :no_content }
end
end
end
Gemfile
-----
source 'https://rubygems.org'
gem 'rails', '3.2.6'
gem "mongoid", "~> 3.0.0"
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'execjs'
gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
gem 'stringex'
gem 'mongoid_slug', :git => 'https://github.com/digitalplaywright/mongoid-slug', :branch => 'bugfix-find'
Gems
-----
$> bundle show
Gems included by the bundle:
* actionmailer (3.2.6)
* actionpack (3.2.6)
* activemodel (3.2.6)
* activerecord (3.2.6)
* activeresource (3.2.6)
* activesupport (3.2.6)
* arel (3.0.2)
* builder (3.0.0)
* bundler (1.1.5)
* coffee-rails (3.2.2)
* coffee-script (2.2.0)
* coffee-script-source (1.3.3)
* erubis (2.7.0)
* execjs (1.4.0)
* hike (1.2.1)
* i18n (0.6.0)
* journey (1.0.4)
* jquery-rails (2.1.1)
* json (1.7.5)
* libv8 (3.3.10.4)
* mail (2.4.4)
* mime-types (1.19)
* mongoid (3.0.4)
* mongoid_slug (0.20.0 48b74bd)
* moped (1.2.0)
* multi_json (1.3.6)
* origin (1.0.6)
* polyglot (0.3.3)
* rack (1.4.1)
* rack-cache (1.2)
* rack-ssl (1.3.2)
* rack-test (0.6.1)
* rails (3.2.6)
* railties (3.2.6)
* rake (0.9.2.2)
* rdoc (3.12)
* sass (3.2.1)
* sass-rails (3.2.5)
* sprockets (2.1.3)
* stringex (1.4.0)
* therubyracer (0.10.2)
* thor (0.16.0)
* tilt (1.3.3)
* treetop (1.4.10)
* tzinfo (0.3.33)
* uglifier (1.2.7)
Gem list
-------
$> gem list
*** LOCAL GEMS ***
actionmailer (3.2.6)
actionpack (3.2.6)
activemodel (3.2.8, 3.2.6)
activerecord (3.2.6)
activeresource (3.2.6)
activesupport (3.2.8, 3.2.6)
arel (3.0.2)
bson (1.6.4)
bson_ext (1.6.4)
builder (3.0.0)
bundler (1.1.5)
coffee-rails (3.2.2)
coffee-script (2.2.0)
coffee-script-source (1.3.3)
daemon_controller (1.0.0)
daemons (1.1.9)
erubis (2.7.0)
eventmachine (0.12.10)
execjs (1.4.0)
fastthread (1.0.7)
hike (1.2.1)
i18n (0.6.0)
journey (1.0.4)
jquery-rails (2.1.1, 2.0.2)
json (1.7.5, 1.7.3)
libv8 (3.3.10.4 x86_64-linux)
mail (2.4.4)
mime-types (1.19)
mongo (1.6.4, 1.6.2)
mongoid (3.0.4, 3.0.1, 2.4.12, 2.0.2)
moped (1.2.0, 1.1.3)
multi_json (1.3.6)
origin (1.0.6, 1.0.4)
passenger (3.0.14)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
rack-protection (1.2.0)
rack-ssl (1.3.2)
rack-test (0.6.1)
rails (3.2.6)
railties (3.2.6)
rake (0.9.2.2)
rdoc (3.12)
rubygems-bundler (1.0.3)
rvm (1.11.3.5)
sass (3.2.1, 3.1.20)
sass-rails (3.2.5)
sinatra (1.3.2)
sprockets (2.4.5, 2.1.3)
sqlite3 (1.3.6)
stringex (1.4.0)
therubyracer (0.10.2, 0.10.1)
thin (1.4.1)
thor (0.16.0, 0.15.4)
tilt (1.3.3)
treetop (1.4.10)
tzinfo (0.3.33)
uglifier (1.2.7, 1.2.6)
Gemfile.lock
-----------
GIT
remote: https://github.com/digitalplaywright/mongoid-slug
revision: 8b5a112d8324c254cccd602348bac04a823ba5fc
specs:
mongoid_slug (0.10.0)
mongoid (~> 3.0)
stringex (~> 1.4)
GEM
remote: https://rubygems.org/
specs:
actionmailer (3.2.6)
actionpack (= 3.2.6)
mail (~> 2.4.4)
actionpack (3.2.6)
activemodel (= 3.2.6)
activesupport (= 3.2.6)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.1)
rack (~> 1.4.0)
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.1.3)
activemodel (3.2.6)
activesupport (= 3.2.6)
builder (~> 3.0.0)
activerecord (3.2.6)
activemodel (= 3.2.6)
activesupport (= 3.2.6)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activeresource (3.2.6)
activemodel (= 3.2.6)
activesupport (= 3.2.6)
activesupport (3.2.6)
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
builder (3.0.0)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.3.3)
erubis (2.7.0)
execjs (1.4.0)
multi_json (~> 1.0)
hike (1.2.1)
i18n (0.6.0)
journey (1.0.4)
jquery-rails (2.1.1)
railties (>= 3.1.0, < 5.0)
thor (~> 0.14)
json (1.7.5)
libv8 (3.3.10.4)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.19)
mongoid (3.0.4)
activemodel (~> 3.1)
moped (~> 1.1)
origin (~> 1.0)
tzinfo (~> 0.3.22)
moped (1.2.0)
multi_json (1.3.6)
origin (1.0.6)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
rack (>= 0.4)
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
rack (>= 1.0)
rails (3.2.6)
actionmailer (= 3.2.6)
actionpack (= 3.2.6)
activerecord (= 3.2.6)
activeresource (= 3.2.6)
activesupport (= 3.2.6)
bundler (~> 1.0)
railties (= 3.2.6)
railties (3.2.6)
actionpack (= 3.2.6)
activesupport (= 3.2.6)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
sass (3.2.1)
sass-rails (3.2.5)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
sprockets (2.1.3)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
stringex (1.4.0)
therubyracer (0.10.2)
libv8 (~> 3.3.10)
thor (0.16.0)
tilt (1.3.3)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.33)
uglifier (1.2.7)
execjs (>= 0.3.0)
multi_json (~> 1.3)
PLATFORMS
ruby
DEPENDENCIES
coffee-rails (~> 3.2.1)
execjs
jquery-rails
mongoid (~> 3.0.0)
mongoid_slug!
rails (= 3.2.6)
sass-rails (~> 3.2.3)
stringex
therubyracer
uglifier (>= 1.0.3)
-----
$> ruby --version
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
$> rvm --version
rvm 1.14.6 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
$> rvm list
rvm rubies
=* ruby-1.9.3-p194 [ x86_64 ]
# => - current
# =* - current && default
# * - default
$> uname -a
Linux localhost.mkf 2.6.32-279.5.1.el6.x86_64 #1 SMP Tue Aug 14 23:54:45 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
CentOS 6.3
$> nginx -v
nginx version: nginx/1.2.2
$> passenger -v
Phusion Passenger version 3.0.14
"Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
$> mongo -version
MongoDB shell version: 2.0.7
$> rails -v
Rails 3.2.6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment