Skip to content

Instantly share code, notes, and snippets.

View ka8725's full-sized avatar
πŸš€
Building Web and Mobile apps

Andrei Kaleshka ka8725

πŸš€
Building Web and Mobile apps
View GitHub Profile
module Mixin::ContentFilter
extend ActiveSupport::Concern
included do
scope :by_creation, order("#{ name.tableize }.created_at DESC")
scope :recent, -> { where{ created_at >= 7.days.ago } }
end
module ClassMethods
def top_items(limit = nil)
@ka8725
ka8725 / gist:3338129
Created August 13, 2012 08:14
Nginx service file
#! /bin/sh
# BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
[apsadmin@www ~]$ ps aux | grep http
root 1319 0.0 0.0 240636 788 ? Ss 03:43 0:03 /usr/sbin/httpd
apache 1380 0.0 0.1 240932 3216 ? S 03:43 0:00 /usr/sbin/httpd
apache 9964 0.0 0.1 241348 3376 ? S 10:24 0:00 /usr/sbin/httpd
apache 11064 0.0 0.0 240960 1144 ? S 11:05 0:00 /usr/sbin/httpd
apache 11262 0.0 0.0 240944 1500 ? S 11:12 0:00 /usr/sbin/httpd
apache 11639 0.0 0.0 240944 332 ? S 11:31 0:00 /usr/sbin/httpd
apache 11671 0.0 0.0 240940 364 ? S 11:32 0:00 /usr/sbin/httpd
apache 11672 0.0 0.1 241216 2844 ? S 11:32 0:00 /usr/sbin/httpd
apache 11734 0.0 0.1 240880 3272 ? S 11:34 0:00 /usr/sbin/httpd
def self.add_before_filter(controller_class, method, *args)
options = args.extract_options!
resource_name = args.first
before_filter_method = options.delete(:prepend) ? :prepend_before_filter : :before_filter
controller_class.send(before_filter_method, options.slice(:only, :except, :if, :unless)) do |controller|
controller.class.cancan_resource_class.new(controller, resource_name, options.except(:only, :except, :if, :unless)).send(method)
end
end
class Group::InvitationsController < ApplicationController
load_resource :group
before_filter :authorize_invitations, only: [:new, :create]
def new
already_invited_user_ids = @group.group_invitations.by_user(current_user).pluck(:invitee_id) | @group.user_ids
@to_invite = { friends: current_user.friends.includes(:profile),
followers: current_user.followers.includes(:profile),
without_ids: already_invited_user_ids }
end
class ContentItemsController < ApplicationController
before_filter :init_resource, :authorize_content_item
def index
@popular_content_items = ContentItem.search_with_filter(params).
sx_active.sx_ordered("votes_count")
if params[:category_id].blank?
if signed_in?
@friends_content_items = ContentItem.search_with_filter(params).
class Event::InvitationsController < ApplicationController
load_resource :event
before_filter :authorize_resource
def new; end
def create
unless params[:users_to_invite].blank?
ids = { groups: [], users: [] }
create_table "groups", :force => true do |t|
t.string "name"
t.text "description"
t.string "access_type"
t.integer "creator_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "membership_approval", :default => "all", :null => false
t.string "posting_permission", :default => "all", :null => false
t.boolean "fan_zone", :default => false
class CurrentUser::ContentSets::ContentItemsController < InheritedResources::Base
belongs_to :content_set
private
def begin_of_association_chain
current_user
end
end
➜ engine git:(master) curl -X POST http://new.private-tutor.ru/entry_submissions/orders.json
{"errors":{"_slug":["can't be blank"],"name":["can't be blank"],"phone":["can't be blank"],"email":["can't be blank"]}}%
➜ engine git:(master) curl -X POST --data "content[name]=a&content[email]=a&content[phone]=a" http://new.private-tutor.ru/entry_submissions/orders.json