A collection of rails code snippets that I'm finding useful and want to commit somewhere.
Wednesday, March 6, 2013
Saving User Location · intridea/omniauth Wiki · GitHub
Customizing the callback of an OAuth request using Omniauth is pretty simple. In you sessions controller where you save the OAuth token, simply add a redirect to omniauth.origin or some other desired destination. omniauth.origin saves the user's last location using the http_referrer.
Tuesday, February 26, 2013
Wrap Long Strings in Rails
Below is a helper method to wrap long strings.
def wrap(content) sanitize(raw(content.split.map{ |s| wrap_long_string(s) }.join(' '))) end private def wrap_long_string(text, max_width = 30) zero_width_space = "​" regex = /.{1,#{max_width}}/ (text.length < max_width) ? text : text.scan(regex).join(zero_width_space) end
Pushing to Heroku after Model Migration
Just some stuff to remember after after pushing a rails project to Heroku or some other PaaS when it contains a migration.
In the Terminal:
$ git push heroku
$ heroku pg:reset DATABASE
$ heroku run rake db:migrate
$ heroku run rake db:populate # if you have a db rake utility to fill your database with sample data
Subscribe to:
Posts (Atom)