Skip to content

Instantly share code, notes, and snippets.

View bondarolik's full-sized avatar
🖥️
Coding now

V. Bruk bondarolik

🖥️
Coding now
View GitHub Profile
@bondarolik
bondarolik / select_box_controller.js
Created May 14, 2024 13:54
Stimulus and select example
// stimulus controller
export default class extends Controller {
static targets = ["roleDescription", "roleDescriptionNone", "selectBox"]
connect() {
// actualizar role list si select tiene algo definido
this.updateRolesList()
}
updateRolesList() {
@bondarolik
bondarolik / create_users_migration_and_rake_task.rb
Created April 7, 2023 20:05
User Table Creation and Data Population within Rake task
# Run rake task from migration file
class CreateUsers < ActiveRecord::Migration [7.0]
def change
create_table :users do It| t.string :first_name t.string :last_name
t. string email, index: { unique: true }
# other columns
t. timestamps
end
@bondarolik
bondarolik / index.html.slim
Last active April 7, 2023 20:06
Dynamic Search with Turbo Frames
# in posts/index.html.slim
= form_for posts_path, method: :get, html: { data: { turbo_frame: 'posts', turbo _action: 'advance' } } do
= search field tag :g, params[:q], placeholder: 'Search..
= turbo frame tag 'posts' do
= render partial: 'posts/post', collection: @posts
= pagy _nav (@pagy)
# It will dynamically update the re attribute on the turbo-frame.
# So the content will be reloaded in AJAX for every search.
@bondarolik
bondarolik / vps.md
Last active April 16, 2022 19:40
VPS setup for Ruby on Rails with 2 environments

Create new droplet (or Amazon Instance)

Use Ubuntu 20+ (any LTS version). Recommended hardware for production: 4CPU/ RAM 8Gb / SSD 80Gb

For staging could less power.

If you need, prepare Bucket S3/Spaces and RDS database droplet/instance.

Prepare your VPS

@bondarolik
bondarolik / gist:2b93076739cfcef0f1fce5f89ef74c5c
Created November 16, 2021 14:34
Tarea técnica para RoR Dev Mid - ActiveRecord
Armar una aplicación Rails que pueda cumplir siguiente:
===== Base:
1. Ruby 3.0.1
2. Rails (6.1.4)
3. Para Front podes usar Importmaps, TWBS, SimpleForms, etc.
4. Foco en Backend
5. Frontend no hace falta pulir 100% (con que pueda hacer un submit y procesar formulario - OK)
6. Donde se aplica podes utilizar Scaffold
@bondarolik
bondarolik / application_controller.rb
Created August 27, 2021 16:36
Devise for Application Controrller
# frozen_string_literal: true
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :configure_permitted_parameters, if: :devise_controller?
before_action :authenticate_user!
def after_sign_in_path_for(resource)
@bondarolik
bondarolik / settings.json
Created February 27, 2021 14:08
Settings for VSCode
{
"workbench.startupEditor": "newUntitledFile",
"window.zoomLevel": 0,
"editor.fontSize": 14,
"files.autoSave": "afterDelay",
"editor.tabSize": 2,
"editor.rulers": [120],
"editor.wordWrapColumn": 120,
"editor.wordWrap": "on",
@bondarolik
bondarolik / rbenv_ruby222.md
Created January 11, 2021 14:54
Unable to install ruby 2.2.2 with rbenv on macOS Big Sur

Ruby < 2.5 fails to install on macOS Big Sur with rbenv because xCode 12 removes outdated packages and it's impossible to rollback to xCode 11.5 and Commandline Tools older version than actual. There are few steps to fix this.

1. Add openssl@1.0.2 with brew

brew install rbenv/tap/openssl@1.0

# view more details at https://stackoverflow.com/questions/59337838/openssl-1-0-2m-on-macos
@bondarolik
bondarolik / modal_remote
Created July 25, 2019 14:30
Fire modal window and load contents from url
# VIEW where we have a link to fire modal. F.e., index.html.haml
# ...
= link_to "Edit form from modal", "#", title: "Title for modal window", data: { toggle: "modal", "load-url": edit_item(item), target: "#modalEditItem" }, class: "btn btn-sm btn-default"
# In the same view or corresponding JS asset
= content_for :scripts do
:javascript
$(document).ready(function(){
$('#modalEditItem').on('show.bs.modal', function (e) {
// load form (or other content) from remote url
@bondarolik
bondarolik / gist:24f9ed1b142825feea23852626320484
Created June 10, 2019 13:46
SimpleForms select with boolean and custom label
= f.input :got_franch, label: false, as: :select, required: true, input_html: {class: "js-select2 selector default-input-contact b-gray f-13", data: {placeholder: ("")}}
= f.input :got_franch, as: :select,
collection: [ ['Si', true], ['No', false] ],
label: false,
required: false
input_html: {
class: "js-select2 selector default-input-contact b-gray f-13"
}