Skip to content

Instantly share code, notes, and snippets.

View davinmsu's full-sized avatar
🐖
Thinking about old friends

Ivan Dashkevich davinmsu

🐖
Thinking about old friends
View GitHub Profile
@davinmsu
davinmsu / routes.rb
Created January 12, 2014 12:01
negative constraints for rails routing
match '/:id', to: 'refinery/blog/categories#show', constraints: { id: /(?!.*?refinery).*/ }
@davinmsu
davinmsu / company.rb
Created February 3, 2014 17:34
remove duplicates from activerecord
def self.dedupe
# find all models and group them on keys which should be common
grouped = all.group_by{|model| [model.title,model.info,model.address,model.phone] }
grouped.values.each do |duplicates|
# the first one we want to keep right?
first_one = duplicates.shift # or pop for last one
# if there are any more left, they are duplicates
# so delete all of them
duplicates.each{|double| double.destroy} # duplicates can now be destroyed
end
$('[data-modal]').click(function(e){
e.preventDefault();
$($(this).data('modal')).modal().open({
onOpen: function(el){
$('.like').click(function(e){
e.preventDefault();
if ($(this).hasClass('u_like')) {
$.ajax({
= link_to dialog_path dialog.participant.id, class: 'person'
img.person src="http://lorempixel.com/80/80/"
p
= "#{dialog.participant.name} #{dialog.participant.last_name}"
})(jQuery);
(function($) {
$.noty.themes.defaultTheme = {
name: 'defaultTheme',
helpers: {
borderFix: function() {
if (this.options.dismissQueue) {
var selector = this.options.layout.container.selector + ' ' + this.options.layout.parent.selector;
switch (this.options.layout.name) {
class ApplicationController < ActionController::Base
check_authorization unless: :devise_controller?
protect_from_forgery
before_action :cancan_patch, :create_user
protected
def cancan_patch
patched_controllers = %w(orders invoices)
if request.post? && action_name == 'create' && patched_controllers.include?(controller_name)
resource = controller_name.singularize.to_sym
def market
if params[:order_id] && params[:order_status]
order = Order.find(params[:order_id])
if params[:order_status] == :declined
current_user.decline_order order # исключает заказ из списка доступных
else
current_user.accept_like order # записывает исполнение заказа, исключает его из доступных заказов
end
end
@order == current_user.get_avaliable_order # возвращает доступный для этого пользователя заказ
def create_documents
order = self.order
customer_doc = order.documents.create!
contractor_doc = self.documents.create!
customer_doc.tranzactions.create! account_id: order.user.accounts.transit.id, amount: (order.price * -1)
contractor_doc.tranzactions.create! account_id: self.user.accounts.transit.id, amount: (order.price * +1)
end
h1 Маркет
br
- if @order.nil?
h2 Заказы отсутствуют
- else
h2 =' @order.price
=' link_to 'Лайк', process_operation_order_path(id: @order.id, order_status: :accepted), method: :post
= link_to 'Отклонить', process_operation_order_path(id: @order.id, order_status: :declined), method: :post
-
class Setting < ActiveRecord::Base
enum type: {integer: 0, string: 1, storage: 2}
enum_features :type
store :value, coder: JSON
after_find :match_types
before_save :save_types
validates :value, numericality: { only_integer: true }, if: 'integer?'
validates :title, uniqueness: true