0%

Haml http://haml.info

Haml to Html http://www.htmltohaml.com/

GitHub Flow http://scottchacon.com/2011/08/31/github-flow.html

  • Anything in the master branch is deployable
  • To work on something new, create a descriptively named branch off of master (ie: new-oauth2-scopes)
  • Commit to that branch locally and regularly push your work to the same named branch on the server
  • When you need feedback or help, or you think the branch is ready for merging, open a pull request
  • After someone else has reviewed and signed off on the feature, you can merge it into master
  • Once it is merged and pushed to ‘master’, you can and should deploy immediately
Read more »

With polymorphic associations, one class can belong_to more than one type of another class. In other words, this is not polymorphism in the typical object-oriented sense of the word; rather, it is something unique to Rails.

In the Case of Models with Comments

For example, you might have a Comment model that belongs to either Timesheet model or BillableWeek model.

Here is a migration that will create the comments table:

1
2
3
4
5
6
7
8
9
10
11
class CreateComments < ActiveRecord::Migration
def change
create_table :comments do |t|
t.text :content
t.references :commentabel, polymorphic: true
# t.integer :commentable_id
# t.string :commentable_type
t.timestamps
end
end
end
Read more »

Simple password authentication is easy to do with has_secure_password. Here you will learn how to make a complete Sign Up, Log In, and Log Out process as well as restrict access to certain actions.

1. User model

1.1 database migrations

1
$ rails g migration create_users
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class CreateUsers < ActiveRecord::Migration
def up
create_table :users do |t|
t.string :name
t.string :email
t.string :password
t.string :remember_token
t.timestamps
end
end

def down
drop_table :users
end
end

1.2 the model file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class User < ActiveRecord::Base
attr_accessible :name, :email, :password, :password_confirmation, :remember_token
has_secure_password

before_save { email: downcase! }
before_save :create_remember_token

VALID_EMAIL_REGEX = /\A[\w+\-.][email protected][a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: ture, format: { with: VALID_EMAIL_REGEX },
uniqueness: {case_sensitive: false}
validates :name, presence: true
validates :password, presence: true, length: { minimum: 6 }
validates :password_confirmation, presence: true
after_validates { self.errors.messages.delete(:password_digest) }

private
def create_remember_token
self.remember_token = SecureRandom.urlsafe_base64
end
end
Read more »