Skip to content

Instantly share code, notes, and snippets.

View VictorTpo's full-sized avatar

Victor Thépaut VictorTpo

View GitHub Profile

Projects Controllers

Client side

2 kinds of controllers :

  • basic (for project with only two fields [name and descritpion]
  • classic (with specific fields)

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
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
# gemfile
gem 'virtus'
# view
render 'forms/errors', form: @form
form_for @form, url: my_path do |f|
 f.input
Tracking.all
> id: 1, label: button_1, page: page_1
> id: 2, label: button_1, page: page_1
> id: 3, label: button_2, page: page_2
> id: 4, label: button_1, page: page_2
> id: 5, label: button_1, page: page_2
> id: 6, label: button_2, page: page_1
module Bar
  def my_method
    'inside module'
  end
end

class Foo
  include Bar
 
class RelationshipAnalyzesController < ApplicationController
  def show
    @search = @analyze.search_results(params)
    @results = @search.results.map { |result| AnalyzeResultPresenter.new(result) }
  end
end
class Vilain
  attr_accessor :name, :kills
end
class VilainPresenter
  include ActionView::Helpers::NumberHelper
 
# link if
<%= link_to_if obj.method?, obj.show_blabla, url %>
# WRONG
class CleanSql
def initialize
@clent = Mysql2::Client.new
end
end
# > 10_000_000.times { CleanSql.new }