Skip to content

Instantly share code, notes, and snippets.

View dyanagi's full-sized avatar
😀
Trying new things

Michael (Daichi) Yanagi dyanagi

😀
Trying new things
  • Vancouver, BC
View GitHub Profile
@dyanagi
dyanagi / _links.html.erb
Last active October 26, 2019 07:17
Customized Devise view (the links component) with Bulma CSS framework
@dyanagi
dyanagi / new.html.erb
Last active October 26, 2019 07:16
Customized Devise view (the Sign-Up page) with Bulma CSS framework
<%# part of this article: https://medium.com/@dyanagi/a-bulma-form-builder-for-ruby-on-rails-applications-aef780808bab %>
<div class="section">
<div class="container">
<div class="content is-medium is-narrow">
<h2><%= t('.sign_up') %></h2>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= render "layouts/error_messages", resource: resource %>
@dyanagi
dyanagi / bulma_form_builder.rb
Last active April 13, 2020 11:53
The Rails form builder for Bulma
# config/initializers/bulma_form_builder.rb
# There are a few things to mention:
# 1) See the article at the URL for sample code with screenshots and more information.
# URL: https://medium.com/@dyanagi/a-bulma-form-builder-for-ruby-on-rails-applications-aef780808bab
# 2) This may not have covered all form controls.
# Form builder for Bulma
# Reference: https://bulma.io/documentation/form/
class BulmaFormBuilder < ActionView::Helpers::FormBuilder
@dyanagi
dyanagi / constants_vs_class_methods.rb
Last active September 22, 2019 18:04
Ruby constants vs class methods
class Example
NAME = "this is constant"
SECRET_NAME = "this is a secret name"
private_constant :SECRET_NAME
def self.foo
@foo ||= "this is foo"
end
def self.bar
@dyanagi
dyanagi / user.rb
Last active October 5, 2019 23:29
Ideas for organizing macro style methods on Rails
# frozen_string_literal: true
# Macro Style Methods style guide (DRAFT)
#
# Let me know if you have a good idea! This is still a draft.
#
# Reference: https://github.com/rubocop-hq/rails-style-guide#macro-style-methods
class User < ActiveRecord::Base
include Sortable
extend SomethingSpecial
@dyanagi
dyanagi / dev.rake
Last active September 25, 2019 05:09
A Rake task file that populates example data for development in Ruby on Rails
# lib/tasks/dev.rake
if Rails.env.development?
namespace :dev do
desc 'Drop, create, load schema, migrate, seed, and populate sample data'
task prepare: ['db:drop', 'db:create', 'db:schema:load',
'db:migrate', 'db:seed', :populate_sample_data] do
puts 'Ready to go!'
end
desc 'Populates the database with sample data'
@dyanagi
dyanagi / ruby-on-rails-tools.md
Last active September 11, 2019 06:01
Tools for Ruby/Rails projects

Tools for Ruby/Rails projects

Rails Best Practices

bundle e rails_best_practices

i18n-tasks

Use this to organize translations and auto-translate missing ones

bundle e i18n-tasks normalize
@dyanagi
dyanagi / rails-bootstrap-loader.scss
Last active September 18, 2019 00:18
SASS example on Bootstrap 4 with Font Awesome
@import "bootstrap";
@import "font-awesome";
// Fix the issue that this block does not show
// https://github.com/twbs/bootstrap/issues/23454#issuecomment-468657049
.invalid-feedback {
display: block;
}
// Section
@dyanagi
dyanagi / ruby_protected_private.md
Last active April 5, 2019 19:16
Examples in using "protected" and "private" in Ruby

Protected Methods in Ruby

class Person
  def initialize(age)
    @age = age
  end

  def is_how_many_younger_than(other_person)
 age - other_person.age
@dyanagi
dyanagi / i18n-tasks.yml
Last active March 30, 2019 18:29
Ruby on Rails i18n-tasks setting example
# i18n-tasks finds and manages missing and unused translations: https://github.com/glebm/i18n-tasks
# The "main" locale.
base_locale: en
## All available locales are inferred from the data by default. Alternatively, specify them explicitly:
locales: [en, ja, zh-CA, zh-TW]
## Reporting locale, default: en. Available: en, ru.
internal_locale: en
# Read and write translations.