Skip to content

Instantly share code, notes, and snippets.

class DemoController < ApplicationController
before_filter :define_some_variables, only: [:index, :hello]
def index
# Renders the action it would render if it were the "hello" action.
# render({:action => 'hello'}) # This is the old way, Rails 1.x.
# Specifies the template to render.
render({:tamplate => 'demo/hello'})
@m4tm4t
m4tm4t / gist:4241818
Created December 8, 2012 20:38
JS format is doing something with layout ??
#
# With layout
#
Started GET "/redaction/actus/3/assets?_=1355002463845" for ::ffff:192.168.0.254 at 2012-12-08 21:34:23 +0000
Processing by Redaction::AssetsController#index as JS
Parameters: {"_"=>"1355002463845", "actu_id"=>"3"}
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Actu Load (1.7ms) SELECT "articles".* FROM "articles" WHERE "articles"."type" IN ('Actu') AND "articles"."id" = $1 LIMIT 1 [["id", "3"]]
Rendered redaction/assets/index.js.erb (0.1ms)
Completed 200 OK in 31ms (Views: 17.6ms | ActiveRecord: 2.3ms)
class Article
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Document::Taggable # https://github.com/chebyte/mongoid-simple-tags
## Fields ##
field :title, type: String
## Accessors ##
@m4tm4t
m4tm4t / active_record_extensions.rb
Created June 18, 2012 15:48
Update counters monkey patch when an association get updated
module FixUpdateCounters
def fix_updated_counters
self.changes.each {|key, value|
# key should match /master_files_id/ or /bibls_id/
# value should be an array ['old value', 'new value']
if key =~ /_id/
changed_class = key.sub(/_id/, '')
# Get real class of changed attribute, so work both with namespaced/normal models
@m4tm4t
m4tm4t / clear_all.rake
Created April 16, 2012 21:26
Clean a rails app
task :clear_all do
%w(tmp:clear log:clear assets:clean).each do |t|
puts "Running #{t}"
task(t).execute
end
end
@m4tm4t
m4tm4t / gist:1843039
Created February 16, 2012 07:45
web-app-theme pagination hack for kaminari
/* pagination (base.css) */
.pagination a,span {
float: left;
}
.pagination span.current, span.gap {
padding: 2px 5px;
margin-right: 5px;
border-style: solid;
@m4tm4t
m4tm4t / Ice-3.4.2-db5.patch
Created January 16, 2012 04:21
Patch for Ice-3.4.2 to work with Berkeley DB 5.X.
--- ./cpp/src/Freeze/MapI.cpp
+++ ./cpp/src/Freeze/MapI.cpp
@@ -1487,10 +1487,10 @@
try
{
-#if DB_VERSION_MAJOR != 4
-#error Freeze requires DB 4.x
+#if DB_VERSION_MAJOR < 4
+#error Freeze requires DB 4.x or greater
CREATE OR REPLACE FUNCTION from_unixtime(integer) RETURNS timestamp AS '
SELECT to_timestamp($1)::timestamp AS result
' LANGUAGE 'SQL';
#ifdef _DatabasePostgre_H
LoginDatabase.PExecute("INSERT INTO account_banned VALUES ('%u',round(date_part('epoch',now())),round(date_part('epoch',now()))+'%u','MaNGOS realmd','Failed login autoban',1)",acc_id, WrongPassBanTime);
#else
LoginDatabase.PExecute("INSERT INTO account_banned VALUES ('%u',UNIX_TIMESTAMP(),UNIX_TIMESTAMP()+'%u','MaNGOS realmd','Failed login autoban',1)",acc_id, WrongPassBanTime);
#endif
2011-02-12 00:27:30 SQL: DELETE FROM corpse WHERE corpse_type = '0' OR time < (UNIX_TIMESTAMP()-'259200')
2011-02-12 00:27:30 SQL ERROR: function unix_timestamp() does not exist
LINE 1: ...TE FROM corpse WHERE corpse_type = '0' OR time < (UNIX_TIMES...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
2011-02-12 00:27:33 SQL: DELETE FROM creature_respawn WHERE respawntime <= UNIX_TIMESTAMP(NOW())
2011-02-12 00:27:33 SQL ERROR: function unix_timestamp(timestamp with time zone) does not exist
LINE 1: DELETE FROM creature_respawn WHERE respawntime <= UNIX_TIMES...
^