Skip to content

Instantly share code, notes, and snippets.

View kagemusha's full-sized avatar

Michael kagemusha

View GitHub Profile
@kagemusha
kagemusha / gist:1920839
Created February 27, 2012 02:22
Rails Mobile web app setup
Rails 3.2
1. In initializers/mime_types.rb
2. Detection of Mobile Device
I put this is a file called mobile.rb in app/util
module Mobile
#optional for testing
TEST_MOBILE_DEV = false #set true to test on browser
@kagemusha
kagemusha / gist:1890279
Created February 23, 2012 04:44
Javascript: Get page url
url = location.href
e.g. to get anchor
anchor = location.href.split('#')[1]
@kagemusha
kagemusha / gist:1843388
Created February 16, 2012 08:44
rails_admin with renamed model in belongs_to assoc
Tested on: Rails 3.2.1
Will get error if don't add :foreign_key to has_many side of relat:
e.g.
class Song < ActiveRecord::Base
belongs_to :creator, :class_name=>"User" #person who added song entry
class User < ActiveRecord::Base
has_many :created_songs, :class_name=>"Song", :foreign_key => 'creator_id'
@kagemusha
kagemusha / gist:1715379
Created February 1, 2012 05:53
Heroku Rails Cedar Commands
Database (PG):
reset db: heroku pg:reset DATABASE_URL
- type exactly like this DATABASE_URL is assigned by Heroku
- will ask you to confirm your app db)
db:* heroku run rake db:*
- e.g. heroku run rake db:migrate
@kagemusha
kagemusha / gist:1668948
Created January 24, 2012 08:48
JQuery UI Date Formatting
Ref: jquery-rails 1.0.19 (jquery ui 1.8x)
$.datepicker.formatDate 'yy-mm-dd', (new Date(obj.created_at))
If u need time need to do it separately
@kagemusha
kagemusha / gist:1661626
Created January 23, 2012 08:11
JQuery Datatables Errors
Seen on: Datatables 1.8.x
1. c[b[0]] is undefined
Check aoColumns prop. E.g. if obj.name below not defined will cause error. If are using
"aoColumns": [
{ "sWidth": '200px', "mDataProp": "obj.name" },
If are setting col val in "fnRowCallback" prop, set mDataProp to null to avoid this problem.
@kagemusha
kagemusha / gist:1660712
Created January 23, 2012 04:50
JQuery Datatables warning: Requested unknow parameter...
Versions: Datatables 1.8.x
If get error such as:
DataTables warning (table id = 'myTable'): Requested unknown parameter '2'
from the data source for row 0
Means num of columns in table heading and in data as specified in
aoColumns do not match. Making sure are same number should fix this.
@kagemusha
kagemusha / gist:1569836
Created January 6, 2012 09:20
Dump Heroku Postgres DB and load locally
Get the Heroku db as detailed here:
http://devcenter.heroku.com/articles/pgbackups#exporting_via_a_backup
1. heroku pgbackups:capture
2. heroku pgbackups:url <backup_num> #=>backup_url
- get backup_num with cmd "heroku pgbackups"
3. curl -o latest.dump <backup_url>
Then locally do:
$ pg_restore --verbose --clean --no-acl --no-owner -h localhost -U myuser -d mydb latest.dump
@kagemusha
kagemusha / gist:1568472
Created January 6, 2012 01:42
JQuery Datatables, Rails Basic Server-side processing Example with Json obj, Custom Data Display
Tested on: Datatable 1.8.2, Rails 3.1.3
This example uses Coffeescript and Haml (you should too :-) )
The following is an example of Datatables server-side processing of a table
which displays a user's song list including the songs' artist names. In
Rails, Song and Artist are ActiveRecord models in a one artist-many song relat.
1a. the Rails controller code
class SongsController < ApplicationController
@kagemusha
kagemusha / gist:1568446
Created January 6, 2012 01:36
JQuery Datatables: Show/Hide controls
Tested on: Databables 1.8.2
Datatables comes with controls for filtering and pagination. These can be shown and hidden in a couple of ways (all examples in coffeescript):
Way 1
$("#myTable").dataTable
"bPaginate": false, #hide pagination control
"bFilter": false #hide filter control