Skip to content

Instantly share code, notes, and snippets.

View VictorTpo's full-sized avatar

Victor Thépaut VictorTpo

View GitHub Profile
def genderize(word_m, subject, word_f = nil)
  return word_m if male?(subject)
  return word_f if word_f.present?
  word_m + 'e'
end
private
def male?(subject)
  subject.gender.casecmp('male') == 0
end

How to Nested

Let's imagine we want to assign pokemons to trainers.

We are creating a new_trainer form with checkboxes for each pokemon and their names next a checkbox to assign them to this new trainer, like this:

  • Salameche

Projects Controllers

Client side

2 kinds of controllers :

  • basic (for project with only two fields [name and descritpion]
  • classic (with specific fields)
@user = User.new(name: '')
[...]
= text_field_tag :pseudo, nil, value: params[:pseudo] || @user.name
# doesn't work :'(

= text_field_tag :pseudo, nil, value: params[:pseudo].present? ? params[:pseudo] : @user.name.present?
# works, but ugly, x2 character count ! :'(

It worked !

class Ambassador
  include Searchable
end

class Speaker
  include Searchable
end

Before

$ item = Project::Speaker.find(5)
$ item.class.name      
> "Project::Speaker"
$ item.class.name.split('::').first
> "Project"
$ item.class.name.split('::').last
> "Speaker"
scope = Celebrity.find(10).tweet
Celebrity Load (0.5ms)  SELECT  `celebrities`.* FROM `celebrities` WHERE `celebrities`.`id` = 10 LIMIT 1
Tweet Load (38.2ms)  SELECT `tweets`.* FROM `tweets` WHERE `tweets`.`celebrity_id` = 10

Disk size

df -h

Repo size

sudo du -h --max-depth=1

Heavy files

sudo find / -size +500M

Log