Here I'll show you
- How to override devise registrations_controller(related to create/update user account)
- How to change redirect path after updating user
jQuery -> | |
alert "hello" | |
$ -> | |
alert "hello" |
# lib/custom_logger.rb | |
class CustomLogger < Logger | |
def format_message(severity, timestamp, progname, msg) | |
"#{timestamp.to_formatted_s(:db)} #{severity} #{msg}\n" | |
end | |
end | |
logfile = File.open("#{Rails.root}/log/custom.log", 'a') # create log file | |
logfile.sync = true # automatically flushes data to file | |
CUSTOM_LOGGER = CustomLogger.new(logfile) # constant accessible anywhere |
# from https://github.com/ruby-china/ruby-china/blob/master/app/helpers/application_helper.rb | |
MOBILE_USER_AGENTS = 'palm|blackberry|nokia|phone|midp|mobi|symbian|chtml|ericsson|minimo|' + | |
'audiovox|motorola|samsung|telit|upg1|windows ce|ucweb|astel|plucker|' + | |
'x320|x240|j2me|sgh|portable|sprint|docomo|kddi|softbank|android|mmp|' + | |
'pdxgw|netfront|xiino|vodafone|portalmmm|sagem|mot-|sie-|ipod|up\\.b|' + | |
'webos|amoi|novarra|cdm|alcatel|pocket|iphone|mobileexplorer|mobile' | |
def mobile? | |
agent_str = request.user_agent.to_s.downcase | |
return false if agent_str =~ /ipad/ |
require "mysql" | |
# more examples: | |
# http://www.kitebird.com/articles/ruby-mysql.html | |
hostname = 'localhost' | |
username = 'yourname' | |
password = 'password' | |
database = 'mysql' | |
port = 3306 |
# [RAILS_ROOT]/lib/tasks/sample.rake | |
desc "print hello world!" # description. | |
task "hello_world" do # rake task name. | |
p "hello world!" # print "hello world!" | |
end | |
namespace :myapp do | |
desc "import data from somewhere" | |
# load rails environment |
; Ported from https://www.autohotkey.com/board/topic/1257-half-qwerty-one-handed-typing/ | |
; Many thanks to Chris for helping me out with this script. | |
mirror_1 = 0 | |
mirror_2 = 9 | |
mirror_3 = 8 | |
mirror_4 = 7 | |
mirror_5 = 6 | |
mirror_q = p | |
mirror_w = o |
require 'net/http' | |
require 'uri' | |
#1: Simple POST | |
res = Net::HTTP.post_form(URI.parse('http://www.example.com/search.cgi'), | |
{'q' => 'ruby', 'max' => '50'}) | |
puts res.body | |
#2: POST with basic authentication | |
res = Net::HTTP.post_form(URI.parse('http://jack:pass@www.example.com/todo.cgi'), |
# in gemfile i have these lines | |
gem 'sitemap_generator', '2.0.1.pre1' | |
gem 'carrierwave' | |
gem 'fog' |
# in spec/support/omniauth_macros.rb | |
module OmniauthMacros | |
def mock_auth_hash | |
# The mock_auth configuration allows you to set per-provider (or default) | |
# authentication hashes to return during integration testing. | |
OmniAuth.config.mock_auth[:twitter] = { | |
'provider' => 'twitter', | |
'uid' => '123545', | |
'user_info' => { | |
'name' => 'mockuser', |