Skip to content

Instantly share code, notes, and snippets.

@MelnikVasya
MelnikVasya / memoized-helper-methods.md
Created November 18, 2021 11:24 — forked from bloudermilk/memoized-helper-methods.md
Explaining the rationale behind using memoized helper methods for controller resources

Last year I started playing around with using memoized private helper methods in my controllers instead of the traditional instance variable assigns we see in RoR controllers. Here's an example:

class PostsController < ApplicationController
  helper_method :new_post, :post, :posts
  
  def new; end
  def show; end
  def edit; end
 def index; end
@MelnikVasya
MelnikVasya / text.md
Created May 8, 2020 19:27 — forked from davydovanton/text.md
Рефакторинг сервис объекта с монадами и AR

Сегодня попался рельсовый код, в котором используются монады, сервисы и прочее. Решил сделать обзор с объяснением того, что в коде не нравится и что можно исправить.

Данный разбор основан только на личном опыте и избегает попытку написать самый идеальный код на свете. К сожалению пошарить ссылку на код не могу, потому что автор попросил опубликовать анонимно.

Исходные данные

Главная операция, которая вызывается из контроллера выглядит следующим образом:

module Excursion

The Problem is Your Ruby

(Intro)

Stop Trying

Stop trying to be an expert at Rails.

Is it Hard?

@MelnikVasya
MelnikVasya / Enhance.js
Created October 19, 2018 09:29 — forked from sebmarkbage/Enhance.js
Higher-order Components
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {
@MelnikVasya
MelnikVasya / rails http status codes
Created August 27, 2018 11:15 — forked from mlanett/rails http status codes
HTTP status code symbols for Rails
HTTP status code symbols for Rails
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings.
Status Code Symbol
1xx Informational
100 :continue
101 :switching_protocols
102 :processing

Bash

Moving

command description
ctrl + a Goto BEGINNING of command line
ctrl + e Goto END of command line
ctrl + b move back one character
@MelnikVasya
MelnikVasya / Capybara.md
Created May 24, 2018 20:22 — forked from tomas-stefano/Capybara.md
Capybara cheatsheet

Capybara Actions

# Anchor
click_link 'Save'

# Button
click_button 'awesome'

# Both above
@MelnikVasya
MelnikVasya / wait_for_ajax.rb
Created May 24, 2018 20:22 — forked from hugomaiavieira/wait_for_ajax.rb
Wait for ajax on ruby with capybara
# Ajax testing with ruby and capybara
#
# Add this to spec/support
#
# When a link or button starts an ajax request, instead of use Capybara
# click_link, click_button and click_link_or_button methods use click_ajax_link,
# click_ajax_button and click_ajax_link_or_button methods. You can still use
# capybara methods and right after it, call wait_for_ajax method.
#
# This methods will wait until Capybara.default_max_wait_time for the ajax request
@MelnikVasya
MelnikVasya / spec_helper.rb
Created April 4, 2017 16:34 — forked from gbpereira/spec_helper.rb
Clean up carrierwave's files for rspec. Ruby 2.0, Rails 4.0.2.
Dir["#{Rails.root}/app/uploaders/*.rb"].each { |file| require file }
if defined?(CarrierWave)
CarrierWave::Uploader::Base.descendants.each do |klass|
next if klass.anonymous?
klass.class_eval do
def cache_dir
"#{Rails.root}/spec/support/uploads/cache"
end