This file contains hidden or 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
| def add(conn, %{"product_id" => product_id}) do | |
| product = Front.get_product!(product_id) | |
| conn = case conn.assigns[:current_order] do | |
| nil -> | |
| order = Front.create_order_with_product!(product) | |
| conn |> put_session(:order_id, order.id) | |
| order -> | |
| Front.add_product_to_order!(order, product) | |
| conn |
This file contains hidden or 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
| defmodule TranslationFields do | |
| @moduledoc """ | |
| Usage: | |
| defmodule Product do | |
| use TranslationFields | |
| @translated_locales ~w(en fr) | |
| @translated_fields ~w(name description) | |
| schema "products" do |
This file contains hidden or 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 Foo | |
| def self.bar | |
| 42 | |
| end | |
| private | |
| def self.private_bar | |
| "oh noes" | |
| end |
This file contains hidden or 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
| !!undefined | |
| // false | |
| !!"" | |
| // false | |
| !!0 | |
| // false | |
| !!null | |
| // false | |
| !!1 | |
| // true |
This file contains hidden or 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
| [1, 2, 3, 4].map(res => res * 2) | |
| // [2, 4, 6, 8] | |
| ['number', 'of', 'letters'].reduce((m, o) => m += o.length, 0) | |
| // 15 |
This file contains hidden or 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 WizardsController < ApplicationController | |
| before_action :load_user_wizard, except: %i(validate_step) | |
| def validate_step | |
| current_step = params[:current_step] | |
| @user_wizard = wizard_user_for_step(current_step) | |
| @user_wizard.user.attributes = user_wizard_params | |
| session[:user_attributes] = @user_wizard.user.attributes |
This file contains hidden or 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
| module Wizard | |
| module User | |
| STEPS = %w(step1 step2 step3 step4).freeze | |
| class Base | |
| include ActiveModel::Model | |
| attr_accessor :user | |
| delegate *::User.attribute_names.map { |attr| [attr, "#{attr}="] }.flatten, to: :user |
This file contains hidden or 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 User < ApplicationRecord | |
| validates :email, presence: true, format: { with: /@/ } | |
| validates :first_name, presence: true | |
| validates :last_name, presence: true | |
| validates :address_1, presence: true | |
| validates :zip_code, presence: true | |
| validates :city, presence: true | |
| validates :country, presence: true | |
| validates :phone_number, presence: true | |
| end |
This file contains hidden or 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
| # config/environments/production.rb | |
| config.action_mailer.smtp_settings = { | |
| :user_name => ENV['SENDGRID_USERNAME'], | |
| :password => ENV['SENDGRID_PASSWORD'], | |
| :domain => 'your_application_name.herokuapp.com', | |
| :address => 'smtp.sendgrid.net', | |
| :port => 587, | |
| :authentication => :plain, | |
| :enable_starttls_auto => true |
This file contains hidden or 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
| # Exposure pattern to use declarative interfaces in controller (which is the basic feature of the library decent_exposure). | |
| # | |
| # Using this pattern you can dramatically reduce or remove completely the need for instance variables in controllers and views. | |
| # | |
| # Example : | |
| # | |
| # BEFORE (traditional way in Ruby on Rails) | |
| # | |
| # class ArticlesController < ApplicationController | |
| # before_action :load_current_blog |