Skip to content

Instantly share code, notes, and snippets.

View kagemusha's full-sized avatar

Michael kagemusha

View GitHub Profile
@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: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: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:2041160
Created March 15, 2012 01:52
Rails: Specify additional asset files for precompilation
Used on: Rails 3.2.1
If you have more than one set of assets to precompile, need to add using config.assets.precompile
E.g. if have mobile.css and mobile.js to precomp, do the following
In config/environments/production.rb (or whenver env you want precompiled)
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
@kagemusha
kagemusha / gist:2090705
Created March 19, 2012 02:14
JQueryMobile: Link callbacks when href='#'
Circa: 1.1.0rc1
If have href='#', e.g. %a{href: '#', id: 'mylink'}, jqm will not fire an event so callback $('#mylink').click won't get called.
Instead do %a{href: 'javascript:myFunction()', ...}
Ref: http://forum.jquery.com/topic/how-can-i-create-buttons-that-execute-some-javascript-without-linking-to-any-address
@kagemusha
kagemusha / gist:2156971
Created March 22, 2012 08:06
Malformed attribute block
This seems to come from haml.js
Not sure the quintessential case, but I had problems when calling JSON.stringify with a string with an apostrophe in in. Apparentely JSON.stringify can't handle apostrophes.
@kagemusha
kagemusha / gist:2225160
Created March 28, 2012 10:01
Rails 3.x ActionView::MissingTemplate for JSON
ActionView::MissingTemplate (Missing template...)
To fix this, make sure have a render such as:
format.json { render :json=>json_to_render }
If leave out the :json=> will get error
Seems if just do respond_to :json and return @someObj will get error
@kagemusha
kagemusha / gist:2732293
Last active October 5, 2015 01:28
Create new Rails App with Rails App Composer
Install: gem install rails_apps_composer
Create app example:
rails_apps_composer new atm -r devise git haml heroku rails_admin rspec sass seed_database add_user home_page
List Recipes: rails_apps_composer list
Additional Steps
- gemfile
- If using pg: create db
@kagemusha
kagemusha / gist:2853186
Created June 1, 2012 16:00
Custom Domain Heroku
Ref: https://devcenter.heroku.com/articles/custom-domains
For naked domains, fairly simple:
1. Add domain to heroku
$ heroku domains:add www.example.com
2. Add separate A records for each of the following addresses using your DNS management tool (e.g. at godaddy or where your domain name hosted):
75.101.163.44
@kagemusha
kagemusha / gist:2918015
Created June 12, 2012 14:56
rspec troubleshooting
make sure database is clean, as sometimes causes funny errs if not
- e.g. was trying to create objs, but failed silently on a uniqueness constraint, so bombed when supposedly created models asked for their ids