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
require 'test_helper' | |
class ActiveFormTest < ActiveSupport::TestCase | |
class Base | |
attr_reader :model, :nested_units | |
def initialize(model) | |
@model = model | |
@nested_units = [] | |
populate_units |
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 ProjectForm < AbstractForm | |
attribute :name | |
association :tasks, records: 3 do | |
attribute :name | |
association :sub_tasks, records: 3 do | |
attribute :name | |
validates :name, presence: 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
<%= form_for @project_form do |f| %> | |
<% if @project_form.errors.any? %> | |
<div id="error_explanation"> | |
<h2><%= pluralize(@project_form.errors.count, "error") %> prohibited this project from being saved:</h2> | |
<ul> | |
<% @project_form.errors.full_messages.each do |message| %> | |
<li><%= message %></li> | |
<% end %> | |
</ul> |
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
<h2>Email details</h2> | |
<%= f.fields_for :email, @user_form.email do |email| %> | |
<div class="field"> | |
<%= email.label :address %><br> | |
<%= email.text_field :address %> | |
</div> | |
<% 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
<h1>Sign Up</h1> | |
<%= form_for @signup_form do |f| %> | |
<% if @signup_form.errors.any? %> | |
<div class="error_messages"> | |
<h2>Form is invalid</h2> | |
<ul> | |
<% @signup_form.errors.full_messages.each do |message| %> | |
<li><%= message %></li> | |
<% 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
require 'benchmark' | |
def strip_num_tr(number) | |
number.tr('^0-9', '') | |
end | |
def strip_num_gsub(number) | |
number.gsub(/\D/, '') | |
end |