Skip to content

Instantly share code, notes, and snippets.

View a-chernykh's full-sized avatar

Andrey Chernykh a-chernykh

View GitHub Profile
# needs the "hashie" gem in Gemfile
require 'erb'
module Movies
class Application < Rails::Application
settings = ERB.new(IO.read(File.expand_path('../settings.yml', __FILE__))).result
mash = Hashie::Mash.new(YAML::load(settings)[Rails.env.to_s])
mash.each do |key, value|
class CustomDevise::SessionsController < Devise::SessionsController
def create
anonymous_cart = Cart.where(:security_hash => session[:security_hash]).last unless session[:security_hash].nil?
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
set_flash_message :notice, :signed_in
if anonymous_cart && !anonymous_cart.user_id?
resource.cart.delete if resource.cart
anonymous_cart.update_attribute(:user_id, resource.id)
end
sign_in_and_redirect(resource_name, resource)
add_subscription_cart PUT /cart/add_subscription(.:format) {:controller=>"carts", :action=>"add_subscription"}
remove_subscription_cart PUT /cart/remove_subscription(.:format) {:controller=>"carts", :action=>"remove_subscription"}
leave_cart GET /cart/leave(.:format) {:controller=>"carts", :action=>"leave"}
cart POST /cart(.:format) {:controller=>"carts", :action=>"create"}
new_cart GET /cart/new(.:format) {:controller=>"carts", :action=>"new"}
edit_cart GET /cart/edit(.:format) {:controller=>"carts", :action=>"edit"}
cart GET /cart(.:format) {:controller=>"carts", :action=>"show"}
cart PUT /cart(.:format)
IndieAisle::Application.routes.draw do
resource :cart do
member do
put 'add_subscription'
put 'remove_subscription'
get 'leave'
end
end
resource :order
match '/checkout' => 'orders#checkout'
We couldn’t find that file to show.
def mongo=(server)
case server
when String
host, port = server.split(':')
@con = Mongo::Connection.new(host, port)
@db = @con.db('monque')
@mongo = @db.collection('monque')
@workers = @db.collection('workers')
@failures = @db.collection('failures')
@stats = @db.collection('stats')
@a-chernykh
a-chernykh / cancel_zencoder_jobs.rb
Created April 25, 2011 14:55
Cancel all zencoder jobs
# jobs deletion has been permanently disabled by Zencoder
Zencoder::Job.list.body.map {|j| Zencoder::Job.cancel(j['job']['id'].to_i)}
@a-chernykh
a-chernykh / staging.rb
Created May 9, 2011 07:51
whenever + capistrano - custom log path
# Configure whenever
set :whenever_environment, rails_env
set :whenever_output, '/var/www/apps/alt12/current/log/crontab.log'
set :whenever_update_flags, "--update-crontab #{whenever_identifier} --set environment=#{whenever_environment}\\&output=#{whenever_output}" # notice the escaping \& passed to the shell
@a-chernykh
a-chernykh / gist:1006487
Created June 3, 2011 15:08
Error when reconfiguring thinking_sphinx when used with combination with meta_search
[andrey-mbp ~/projects/rails/alt12-site rails3]$ rake ts:config --trace
WARNING: Nokogiri was built against LibXML version 2.7.7, but has dynamically loaded 2.7.3
** Invoke ts:config (first_time)
** Invoke thinking_sphinx:configure (first_time)
** Invoke thinking_sphinx:app_env (first_time)
** Execute thinking_sphinx:app_env
** Execute thinking_sphinx:configure
Generating Configuration to /Users/akhkharu/projects/rails/alt12-site/config/development.sphinx.conf
rake aborted!
Association named 'applications_forums' was not found; perhaps you misspelled it?
@a-chernykh
a-chernykh / gist:1014249
Created June 8, 2011 11:31
prototype-rails with latest Rails error
[andrey-mbp ~/projects/rails/alt12-site rails3]$ rails s
WARNING: Nokogiri was built against LibXML version 2.7.7, but has dynamically loaded 2.7.3
=> Booting Mongrel
=> Rails 3.1.0.rc2 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/Users/akhkharu/.rvm/gems/ruby-1.9.2-head@alt12/gems/actionpack-3.1.0.rc2/lib/action_dispatch/testing/assertions.rb:14:in `<module:Assertions>': uninitialized constant ActionDispatch::Assertions::SelectorAssertions (NameError)
from /Users/akhkharu/.rvm/gems/ruby-1.9.2-head@alt12/gems/actionpack-3.1.0.rc2/lib/action_dispatch/testing/assertions.rb:2:in `<module:ActionDispatch>'
from /Users/akhkharu/.rvm/gems/ruby-1.9.2-head@alt12/gems/actionpack-3.1.0.rc2/lib/action_dispatch/testing/assertions.rb:1:in `<top (required)>'