Learn Geek languages like Big data,Hadoop,Hive,Pig,Sqoop ,flume,Cassandra,Hbase,Ruby On Rails,Python,Java and many more.

Wednesday 13 July 2016


class Person < ApplicationRecord
  validates :name, presence: true
end

 OR

class Person < ApplicationRecord
  validates :name, :login, :email, presence: true
end

class Person < ApplicationRecord
  validates :terms_of_service, acceptance: true
end

class Person < ApplicationRecord
  validates :email, confirmation: true
end

class Product < ApplicationRecord
  validates :legacy_code, format: { with: /\A[a-zA-Z]+\z/,
    message: "only allows letters" }
OR a-z,A-Z,0-9
end

class Person < ApplicationRecord
  validates :name, length: { minimum: 2 }
  validates :bio, length: { maximum: 500 }
  validates :password, length: { in: 6..20 }
  validates :registration_number, length: { is: 6 }
end

class Player < ApplicationRecord
  validates :points, numericality: true
end

class Account < ApplicationRecord
  validates :email, uniqueness: true
end

Monday 4 July 2016

TAGS:

ERB tags                   <%    %>
print ERB tags          <%=  %>
print ERB comment  <%# %>
if block                      <% if %>...<% end %>
if / else                       <% if %>...<% else %>...<% end %>
else tag     else           <% else %>
elsif tag     elsif          <% elsif %>
end block     end        <% end %>
link_to helper             <%= link_to ..., ... %>
form_for helper     form      <%= form_for(@) do %>

Helpers:

   Form Component     Output Code Snippet

   f.submit                       <%= f.submit "Submit"  %>
   f.password_field          <%= f.password_field :attribute %>
   f.text_area                   <%= f.text_area :attribute %>
   f.check_box                 <%= f.check_box :attribute %>
   f.label                          <%= f.label :attribute, "Attribute" %>
   f.text_field                   <%= f.text_field :attribute %>
   f.file_field                    <%= f.file_field :attribute %>
   f.hidden_field              <%= f.hidden_field :attribute %>