Skip to content

Instantly share code, notes, and snippets.

View borisd's full-sized avatar

Boris Dinkevich borisd

View GitHub Profile
@borisd
borisd / gist:8357712
Created January 10, 2014 16:41
Home work for learing OOP
@borisd
borisd / gist:8357829
Last active January 2, 2016 20:38
Git homework

Add yourself

  • On the spreadsheet, there is a "Contacts" sheet, please put your bitbucket user under your name.
  • Send me email so I add you to the repository

Excercise

  • Clone [email protected]:bardelas/all.git
  • Add a file "yourname.txt" with something inside
  • Update the server
@borisd
borisd / gist:8415093
Last active January 3, 2016 05:19
Homework lesson #3

Learn !

Its very important to know Validations and Field types as we will use them alot in our code. Please take the time to read (or at least skim over) the validations list to see what kind of validations are possible.

Create a new model

Some ruby comments

Spaces

You can't have space betwen function and open bracket

This is wrong: hello (params) (Notice the space !)
This is right: hello(params)
This is right: hello( params )

@borisd
borisd / gist:8439500
Created January 15, 2014 16:35
Solutions to Validations
# Validate AGE is above 16
# Validate First Name is longer than 5 characters
# Validate Username is unique
class User < ActiveRecord::Base
attr_accessible(:age, :first_name, :last_name, :username)
validates :age, numericality: { greater_than: 16 }
validates :first_name, length: { minimum: 5 }
@borisd
borisd / gist:8452549
Created January 16, 2014 10:09
Solution to ActiveRecord Validations homework
class Cat < ActiveRecord::Base
attr_accessible :birthdate, :breed, :name
BREEDS = [:arabean, :asian, :bengal, :persian]
# Name must be present and between 5 and 20 characters
validates :name, length: { in: 5..20 }
# Breed must be one of the following: :arabean, :asian, :bengal, :persian
validates :breed, inclusion: { in: BREEDS }
@borisd
borisd / gist:8501979
Created January 19, 2014 08:30
Template for users list
<h1>User list</h1>
<table>
<tr>
<th>Id</th>
<th>Username</th>
</tr>
- For each user
<tr>
@borisd
borisd / gist:8501985
Created January 19, 2014 08:30
Template for user info
<h1>[username] details:</h1>
<table>
<tr>
<th>Username</th>
<td>[username]</td>
</tr>
<tr>
<th>First name</th>
<td>[first name]</td>

Create a new rails project "catz"

Git

In the beginning and after each successful step you make

Create model "User"

  • email: string
@borisd
borisd / gist:8693327
Created January 29, 2014 17:57
Cats table.html
<ul class="media-grid">
<% @cats.each do |cat| %>
<li class='thumbnail'>
<%= link_to cat_path(cat) do %>
<%= image_tag cat.image.url, alt: cat.name %>
<% end %>
<ul class="controls">
<% if can_like?(cat) %><li><%= link_to 'Like', like_cat_path(cat), method: :post, :class => 'btn btn-mini' %></li><% end %>
<% if can_unlike?(cat) %><li><%= link_to 'UnLike', unlike_cat_path(cat), method: :post, :class => 'btn btn-mini' %></li><% end %>
<% if can_edit?(cat) %><li><%= link_to 'Edit', edit_cat_path(cat), :class => 'btn btn-mini' %></li><% end %>