Skip to content

Instantly share code, notes, and snippets.

View aishek's full-sized avatar
👨‍💻

Aleksandr Borisov aishek

👨‍💻
View GitHub Profile
@aishek
aishek / user.rb
Created August 17, 2014 14:09
six rules ror app usage example
# app/models/user.rb
class User < ActiveRecord::Base
include Allowed::UserRules
end
@aishek
aishek / example_controller.rb
Created September 1, 2014 11:25
flash examples
# app/controllers/example_controller.rb
class ExampleController < ActionController::Base
def index
flash.notice = 'Мне не спится, нет огня;'
flash[:alert] = 'Всюду мрак и сон докучный.'
end
end
@aishek
aishek / users_controller.rb
Created September 1, 2014 11:29
rails falsh redirect usage example
class UsersController < ApplicationController
def create
redirect_to root_path, :notice => 'Что тревожишь ты меня?'
end
end
@aishek
aishek / flash_example_controller.rb
Created September 1, 2014 12:48
add_flash_types example
# app/controllers/flash_example_controller.rb
class FlashExampleController < ActionController::Base
add_flash_types :error
def test
redirect_to admin_auth_login_path, :error => 'Вы должны выполнить вход'
end
end
@aishek
aishek / flash_now_example_controller.rb
Created September 1, 2014 12:52
flash now example
# app/controllers/flash_now_example_controller.rb
class FlashNowExampleController < ActionController::Base
def test
flash.now.notice = 'На свете счастья нет, но есть покой и воля'
end
end
<% # app/views/shared/_flashes.html.erb %>
<% flash.each do |key, message| %>
<p class="<%= key %>"><%= message %></p>
<% end %>
@aishek
aishek / commands.sh
Last active August 29, 2015 14:06
gem dump example
# создаём дамп, содержащий только таблицу my_people_texts
#
$ rake dump TABLES='my_people_texts' ASSETS=''
Tables: 100.0%
20140918080518.tgz
# заливаем дамп на сервер
#
$ cap dump:upload LIKE='20140918080518'
...
@aishek
aishek / backup.rake
Last active August 29, 2015 14:06
gem dump + gem whenever scheduled backup example
# lib/backup.rake
task :backup => [:environment] do
# делаем полный дамп базы и ассетов
ENV['TAG'] = 'backup'
Rake::Task['dump'].invoke
# храним 30 последних таких дампов
ENV['TAG'] = 'backup'
ENV['LEAVE'] = '30'
@aishek
aishek / git.diff
Last active August 29, 2015 14:06
No newline at end of file Git warning example
-end
+end
\ No newline at end of file
@aishek
aishek / api.rb
Created September 29, 2014 10:21
grape api Api class usage example
# app/controllers/api.rb
class Api < Grape::API
mount ::Api::V1
end