Skip to content

Instantly share code, notes, and snippets.

git config --global user.name "Your Name"
git config --global user.email [email protected]
git remote add origin https://github.com/<username>/first_app.git # Добавление удалённого репозитория
git init
git add .
git commit -m "Initialize repository"
git push -u origin master
@reiro
reiro / gist:ed6d56a69d22d13834bd
Created May 12, 2015 15:46
Создание Категорий и подкатегорий
rails g model category name:string parent:references
class Category < ActiveRecord::Base
has_many :subcategories, :class_name => "Category", :foreign_key => "parent_id", :dependent => :destroy
belongs_to :parent_category, :class_name => "Category"
end
def index
@category = nil
@categories = Category.find(:all, :conditions => {:parent_id => nil } )
@reiro
reiro / gist:5bc9310c544de43af122
Created May 13, 2015 06:22
Динамические селекты
# Контроллер
def update_service_types
@service_types = ServiceType.where("sto_category_id = ?", params[:sto_category_id])
respond_to do |format|
format.js
end
end
#assets/js/autoservice.js.coffee
$ ->
@reiro
reiro / gist:5939ba5e23cb0343036e
Created May 13, 2015 07:41
Установка Devise для авторизации
gem 'devise'
rails generate devise:install
#config/environments/development.rb:
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
rails generate devise:views
rails generate devise User
rake db:migrate
@reiro
reiro / gist:f362819ce370fe3e83aa
Created May 13, 2015 10:22
Бесконечная пагинация
gem 'will_paginate'
gem 'bootstrap-sass'
gem 'bootstrap-will_paginate'
.paginate(page: params[:page], per_page: 15).order('created_at ASC')
<div id="my-autoservices">
<%= render @autoservices %>
</div>
gem 'activeadmin', github: 'activeadmin'
gem 'devise'
gem 'cancan' # or cancancan
gem 'draper'
gem 'pundit'
rails g scaffold Product name price:decimal category:references
rails g scaffold Category name
rake db:migrate
Category.create name: "Книги"
@reiro
reiro / gist:625a7c4968152e272380
Created May 22, 2015 13:49
Загрузка изображений
http://www.sitepoint.com/asynchronous-file-uploads-rails/ - dragonfly + ajax
https://github.com/markevans/dragonfly
http://markevans.github.io/dragonfly/rails/
http://www.munocreative.com/nerd-notes/justpayme - paperclip
https://github.com/thoughtbot/paperclip
@reiro
reiro / gist:831f610c0c48d3b92e6e
Created May 27, 2015 06:47
Книги по психологии
1. парадокс перфекциониста
2. Сила воли Как развить и укрепить
3. Выйди из зоны комфорта. Измени свою жизнь
4. Психология убеждения
@reiro
reiro / gist:ffc179bb938b324824e3
Created June 1, 2015 13:36
Export and import mysql db
mysqldump db_name > backup-file.sql
mysql -u username -p database_name --force < file.sql
class ParserController < ApplicationController
require 'open-uri'
require 'nokogiri'
require 'mechanize'
require 'thread'
require 'watir-webdriver'
def parse_sto
url = "file:///home/dima/Sites/sto_parser/%D0%A8%D0%B8%D0%BD%D1%8B,%20%D0%B4%D0%B8%D1%81%D0%BA%D0%B8%20%D0%BD%D0%B0%20%D0%B0%D0%B2%D1%82%D0%BE%20%D0%B2%20%D0%9C%D0%B8%D0%BD%D1%81%D0%BA%D0%B5.%20%D0%9C%D0%B0%D0%B3%D0%B0%D0%B7%D0%B8%D0%BD%D1%8B%20%D0%BF%D0%BE%20%D0%BF%D1%80%D0%BE%D0%B4%D0%B0%D0%B6%D0%B5%20%D1%88%D0%B8%D0%BD,%20%D0%BB%D0%B8%D1%82%D1%8B%D1%85%20%D0%B4%D0%B8%D1%81%D0%BA%D0%BE%D0%B2%20%D0%B2%20%D0%91%D0%B5%D0%BB%D0%B0%D1%80%D1%83%D1%81%D0%B8%20-%20%D0%9A%D0%B0%D1%82%D0%B0%D0%BB%D0%BE%D0%B3%20TUT.BY.html"