- Your class can be no longer than a hundred lines of code.
- Your methods can be no longer than five lines of code
- You can pass no more than four parameters and you can't just make it one big hash.
- In your controller, you can only instantiate one object, to do whatever it is that needs to be done.
- Your view can only know about one instance variable.
- Your Rails view should only send messages to that object i.e., no Demeter violations.[ "thunder dome principal". Translated: one model in, one model out! ]
- Rules are meant to be broken if by breaking them you produce better code. [ ...where "better code" is validated by explaining why you want to break the rule to someone else. ]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person | |
def initialize(attributes) | |
attributes.each do |attribute_name, attribute_value| | |
##### Method one ##### | |
# Works just great, but uses something scary like eval | |
# self.class.class_eval {attr_accessor attribute_name} | |
# self.instance_variable_set("@#{attribute_name}", attribute_value) | |
##### Method two ##### | |
# Manually creates methods for both getter and setter and then |
https://github.com/ankane/searchkick
By default, simply adding the call 'searchkick' to a model will do an unclever indexing of all fields (but not has_many or belongs_to attributes).
In practice, you'll need to customize what gets indexed. This is done by defining a method on your model called search_data
def search_data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template lang='pug'> | |
div.drop-zone(:class='{dragging: isDragging }' | |
@dragover.prevent='dragover' | |
@dragenter.prevent='dragover' | |
@drop.prevent.stop='onDrop' | |
@dragleave.prevent='dragleave') | |
div(:class='{ hidden: uploadInProgress }' @click='openFileBrowser') | |
slot | |
i {{label}} | |
input(type='file' :multiple='multiple' ref='input' style='display: none') |
There are trhee diffrent time zones in rails
- System - The server time zone
- Application - Rails application use own time zone
- Database - Default is
UTC
, but do not change it
config.time_zone
should be set when an app dose not support multiple time zones- Do not use Date/Time API using system time zone
- Date could be incorrect by being converted from datetime or time to date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This helper file provides a consistent API for testing Stimulus Controllers | |
// | |
// Use: | |
// import { getHTML, setHTML, startStimulus } from './_stimulus_helper'; | |
// import MyController from '@javascripts/controllers/my_controller'; | |
// | |
// beforeEach(() => startStimulus('my', MyController)); | |
// test('should do something', async () => { | |
// await setHTML(`<button data-controller="my" data-action="my#action">click</button>`); | |
// |