This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
url = location.href | |
e.g. to get anchor | |
anchor = location.href.split('#')[1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |