+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+/*
+ * ----------------------------------------------------------------------------
+ * "THE BEER-WARE LICENSE" (Revision 42):
+ * Michael Hartl wrote this code. As long as you retain this notice you
+ * can do whatever you want with this stuff. If we meet some day, and you think
+ * this stuff is worth it, you can buy me a beer in return.
+ * ----------------------------------------------------------------------------
+ */
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 000000000..ceb9077a5
--- /dev/null
+++ b/README.md
@@ -0,0 +1,15 @@
+# Ruby on Rails Tutorial: sample application
+
+This is the sample application for
+[*Ruby on Rails Tutorial: Learn Web Development with Rails*](http://railstutorial.org/)
+by [Michael Hartl](http://michaelhartl.com/). You can use this reference implementation to help track down errors if you end up having trouble with code in the tutorial. In particular, as a first debugging check I suggest getting the test suite to pass on your local machine:
+
+ $ cd /tmp
+ $ git clone git@github.com:railstutorial/sample_app_2nd_ed.git
+ $ cd sample_app_2nd_ed
+ $ bundle install
+ $ bundle exec rake db:migrate
+ $ bundle exec rake db:test:prepare
+ $ bundle exec rspec spec/
+
+If the tests don't pass, it means there may be something wrong with your system. If they do pass, then you can debug your code by comparing it with the reference implementation.
\ No newline at end of file
diff --git a/README.rdoc b/README.rdoc
deleted file mode 100644
index 7c36f2356..000000000
--- a/README.rdoc
+++ /dev/null
@@ -1,261 +0,0 @@
-== Welcome to Rails
-
-Rails is a web-application framework that includes everything needed to create
-database-backed web applications according to the Model-View-Control pattern.
-
-This pattern splits the view (also called the presentation) into "dumb"
-templates that are primarily responsible for inserting pre-built data in between
-HTML tags. The model contains the "smart" domain objects (such as Account,
-Product, Person, Post) that holds all the business logic and knows how to
-persist themselves to a database. The controller handles the incoming requests
-(such as Save New Account, Update Product, Show Post) by manipulating the model
-and directing data to the view.
-
-In Rails, the model is handled by what's called an object-relational mapping
-layer entitled Active Record. This layer allows you to present the data from
-database rows as objects and embellish these data objects with business logic
-methods. You can read more about Active Record in
-link:files/vendor/rails/activerecord/README.html.
-
-The controller and view are handled by the Action Pack, which handles both
-layers by its two parts: Action View and Action Controller. These two layers
-are bundled in a single package due to their heavy interdependence. This is
-unlike the relationship between the Active Record and Action Pack that is much
-more separate. Each of these packages can be used independently outside of
-Rails. You can read more about Action Pack in
-link:files/vendor/rails/actionpack/README.html.
-
-
-== Getting Started
-
-1. At the command prompt, create a new Rails application:
- rails new myapp (where myapp is the application name)
-
-2. Change directory to myapp and start the web server:
- cd myapp; rails server (run with --help for options)
-
-3. Go to http://localhost:3000/ and you'll see:
- "Welcome aboard: You're riding Ruby on Rails!"
-
-4. Follow the guidelines to start developing your application. You can find
-the following resources handy:
-
-* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
-* Ruby on Rails Tutorial Book: http://www.railstutorial.org/
-
-
-== Debugging Rails
-
-Sometimes your application goes wrong. Fortunately there are a lot of tools that
-will help you debug it and get it back on the rails.
-
-First area to check is the application log files. Have "tail -f" commands
-running on the server.log and development.log. Rails will automatically display
-debugging and runtime information to these files. Debugging info will also be
-shown in the browser on requests from 127.0.0.1.
-
-You can also log your own messages directly into the log file from your code
-using the Ruby logger class from inside your controllers. Example:
-
- class WeblogController < ActionController::Base
- def destroy
- @weblog = Weblog.find(params[:id])
- @weblog.destroy
- logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
- end
- end
-
-The result will be a message in your log file along the lines of:
-
- Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
-
-More information on how to use the logger is at http://www.ruby-doc.org/core/
-
-Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
-several books available online as well:
-
-* Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
-* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
-
-These two books will bring you up to speed on the Ruby language and also on
-programming in general.
-
-
-== Debugger
-
-Debugger support is available through the debugger command when you start your
-Mongrel or WEBrick server with --debugger. This means that you can break out of
-execution at any point in the code, investigate and change the model, and then,
-resume execution! You need to install ruby-debug to run the server in debugging
-mode. With gems, use sudo gem install ruby-debug. Example:
-
- class WeblogController < ActionController::Base
- def index
- @posts = Post.all
- debugger
- end
- end
-
-So the controller will accept the action, run the first line, then present you
-with a IRB prompt in the server window. Here you can do things like:
-
- >> @posts.inspect
- => "[#nil, "body"=>nil, "id"=>"1"}>,
- #"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
- >> @posts.first.title = "hello from a debugger"
- => "hello from a debugger"
-
-...and even better, you can examine how your runtime objects actually work:
-
- >> f = @posts.first
- => #nil, "body"=>nil, "id"=>"1"}>
- >> f.
- Display all 152 possibilities? (y or n)
-
-Finally, when you're ready to resume execution, you can enter "cont".
-
-
-== Console
-
-The console is a Ruby shell, which allows you to interact with your
-application's domain model. Here you'll have all parts of the application
-configured, just like it is when the application is running. You can inspect
-domain models, change values, and save to the database. Starting the script
-without arguments will launch it in the development environment.
-
-To start the console, run rails console from the application
-directory.
-
-Options:
-
-* Passing the -s, --sandbox argument will rollback any modifications
- made to the database.
-* Passing an environment name as an argument will load the corresponding
- environment. Example: rails console production.
-
-To reload your controllers and models after launching the console run
-reload!
-
-More information about irb can be found at:
-link:http://www.rubycentral.org/pickaxe/irb.html
-
-
-== dbconsole
-
-You can go to the command line of your database directly through rails
-dbconsole. You would be connected to the database with the credentials
-defined in database.yml. Starting the script without arguments will connect you
-to the development database. Passing an argument will connect you to a different
-database, like rails dbconsole production. Currently works for MySQL,
-PostgreSQL and SQLite 3.
-
-== Description of Contents
-
-The default directory structure of a generated Ruby on Rails application:
-
- |-- app
- | |-- assets
- | |-- images
- | |-- javascripts
- | `-- stylesheets
- | |-- controllers
- | |-- helpers
- | |-- mailers
- | |-- models
- | `-- views
- | `-- layouts
- |-- config
- | |-- environments
- | |-- initializers
- | `-- locales
- |-- db
- |-- doc
- |-- lib
- | `-- tasks
- |-- log
- |-- public
- |-- script
- |-- test
- | |-- fixtures
- | |-- functional
- | |-- integration
- | |-- performance
- | `-- unit
- |-- tmp
- | |-- cache
- | |-- pids
- | |-- sessions
- | `-- sockets
- `-- vendor
- |-- assets
- `-- stylesheets
- `-- plugins
-
-app
- Holds all the code that's specific to this particular application.
-
-app/assets
- Contains subdirectories for images, stylesheets, and JavaScript files.
-
-app/controllers
- Holds controllers that should be named like weblogs_controller.rb for
- automated URL mapping. All controllers should descend from
- ApplicationController which itself descends from ActionController::Base.
-
-app/models
- Holds models that should be named like post.rb. Models descend from
- ActiveRecord::Base by default.
-
-app/views
- Holds the template files for the view that should be named like
- weblogs/index.html.erb for the WeblogsController#index action. All views use
- eRuby syntax by default.
-
-app/views/layouts
- Holds the template files for layouts to be used with views. This models the
- common header/footer method of wrapping views. In your views, define a layout
- using the layout :default and create a file named default.html.erb.
- Inside default.html.erb, call <% yield %> to render the view using this
- layout.
-
-app/helpers
- Holds view helpers that should be named like weblogs_helper.rb. These are
- generated for you automatically when using generators for controllers.
- Helpers can be used to wrap functionality for your views into methods.
-
-config
- Configuration files for the Rails environment, the routing map, the database,
- and other dependencies.
-
-db
- Contains the database schema in schema.rb. db/migrate contains all the
- sequence of Migrations for your schema.
-
-doc
- This directory is where your application documentation will be stored when
- generated using rake doc:app
-
-lib
- Application specific libraries. Basically, any kind of custom code that
- doesn't belong under controllers, models, or helpers. This directory is in
- the load path.
-
-public
- The directory available for the web server. Also contains the dispatchers and the
- default HTML files. This should be set as the DOCUMENT_ROOT of your web
- server.
-
-script
- Helper scripts for automation and generation.
-
-test
- Unit and functional tests along with fixtures. When using the rails generate
- command, template test files will be generated for you and placed in this
- directory.
-
-vendor
- External libraries that the application depends on. Also includes the plugins
- subdirectory. If the app has frozen rails, those gems also go here, under
- vendor/rails/. This directory is in the load path.
diff --git a/Rakefile b/Rakefile
index af7fdd3cd..e0f380c18 100644
--- a/Rakefile
+++ b/Rakefile
@@ -4,4 +4,4 @@
require File.expand_path('../config/application', __FILE__)
-JamWeb::Application.load_tasks
+SampleApp::Application.load_tasks
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index 9097d830e..8c515ad62 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -12,4 +12,5 @@
//
//= require jquery
//= require jquery_ujs
+//= require bootstrap
//= require_tree .
diff --git a/app/assets/javascripts/sessions.js.coffee b/app/assets/javascripts/sessions.js.coffee
new file mode 100644
index 000000000..761567942
--- /dev/null
+++ b/app/assets/javascripts/sessions.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
diff --git a/app/assets/javascripts/static_pages.js.coffee b/app/assets/javascripts/static_pages.js.coffee
new file mode 100644
index 000000000..761567942
--- /dev/null
+++ b/app/assets/javascripts/static_pages.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
diff --git a/app/assets/javascripts/users.js.coffee b/app/assets/javascripts/users.js.coffee
new file mode 100644
index 000000000..761567942
--- /dev/null
+++ b/app/assets/javascripts/users.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css
index 3192ec897..3b5cc6648 100644
--- a/app/assets/stylesheets/application.css
+++ b/app/assets/stylesheets/application.css
@@ -10,4 +10,4 @@
*
*= require_self
*= require_tree .
- */
+*/
diff --git a/app/assets/stylesheets/custom.css.scss b/app/assets/stylesheets/custom.css.scss
new file mode 100644
index 000000000..78e252c44
--- /dev/null
+++ b/app/assets/stylesheets/custom.css.scss
@@ -0,0 +1,242 @@
+@import "bootstrap";
+
+/* mixins, variables, etc. */
+
+$grayMediumLight: #eaeaea;
+
+@mixin box_sizing {
+ -moz-box-sizing: border-box;
+ -webkit-box-sizing: border-box;
+ box-sizing: border-box;
+}
+
+/* universal */
+
+html {
+ overflow-y: scroll;
+}
+
+body {
+ padding-top: 60px;
+}
+
+section {
+ overflow: auto;
+}
+
+textarea {
+ resize: vertical;
+}
+
+.center {
+ text-align: center;
+ h1 {
+ margin-bottom: 10px;
+ }
+}
+
+/* typography */
+
+h1, h2, h3, h4, h5, h6 {
+ line-height: 1;
+}
+
+h1 {
+ font-size: 3em;
+ letter-spacing: -2px;
+ margin-bottom: 30px;
+ text-align: center;
+}
+
+h2 {
+ font-size: 1.7em;
+ letter-spacing: -1px;
+ margin-bottom: 30px;
+ text-align: center;
+ font-weight: normal;
+ color: $grayLight;
+}
+
+p {
+ font-size: 1.1em;
+ line-height: 1.7em;
+}
+
+
+/* header */
+
+#logo {
+ float: left;
+ margin-right: 10px;
+ font-size: 1.7em;
+ color: white;
+ text-transform: uppercase;
+ letter-spacing: -1px;
+ padding-top: 9px;
+ font-weight: bold;
+ line-height: 1;
+ &:hover {
+ color: white;
+ text-decoration: none;
+ }
+}
+
+/* footer */
+
+footer {
+ margin-top: 45px;
+ padding-top: 5px;
+ border-top: 1px solid $grayMediumLight;
+ color: $grayLight;
+ a {
+ color: $gray;
+ &:hover {
+ color: $grayDarker;
+ }
+ }
+ small {
+ float: left;
+ }
+ ul {
+ float: right;
+ list-style: none;
+ li {
+ float: left;
+ margin-left: 10px;
+ }
+ }
+}
+
+/* miscellaneous */
+
+.debug_dump {
+ clear: both;
+ float: left;
+ width: 100%;
+ margin-top: 45px;
+ @include box_sizing;
+}
+
+/* sidebar */
+
+aside {
+ section {
+ padding: 10px 0;
+ border-top: 1px solid $grayLighter;
+ &:first-child {
+ border: 0;
+ padding-top: 0;
+ }
+ span {
+ display: block;
+ margin-bottom: 3px;
+ line-height: 1;
+ }
+ h1 {
+ font-size: 1.6em;
+ text-align: left;
+ letter-spacing: -1px;
+ margin-bottom: 3px;
+ }
+ }
+}
+
+.gravatar {
+ float: left;
+ margin-right: 10px;
+}
+
+.stats {
+ overflow: auto;
+ a {
+ float: left;
+ padding: 0 10px;
+ border-left: 1px solid $grayLighter;
+ color: gray;
+ &:first-child {
+ padding-left: 0;
+ border: 0;
+ }
+ &:hover {
+ text-decoration: none;
+ color: $blue;
+ }
+ }
+ strong {
+ display: block;
+ }
+}
+
+.user_avatars {
+ overflow: auto;
+ margin-top: 10px;
+ .gravatar {
+ margin: 1px 1px;
+ }
+}
+
+/* forms */
+
+input, textarea, select, .uneditable-input {
+ border: 1px solid #bbb;
+ width: 100%;
+ padding: 10px;
+ height: auto;
+ margin-bottom: 15px;
+ @include box_sizing;
+}
+
+#error_explanation {
+ color:#f00;
+ ul {
+ list-style: none;
+ margin: 0 0 18px 0;
+ }
+}
+
+.field_with_errors {
+ @extend .control-group;
+ @extend .error;
+ }
+
+ /* users index */
+
+.users {
+ list-style: none;
+ margin: 0;
+ li {
+ overflow: auto;
+ padding: 10px 0;
+ border-top: 1px solid $grayLighter;
+ &:last-child {
+ border-bottom: 1px solid $grayLighter;
+ }
+ }
+}
+
+/* microposts */
+
+.microposts {
+ list-style: none;
+ margin: 10px 0 0 0;
+
+ li {
+ padding: 10px 0;
+ border-top: 1px solid #e8e8e8;
+ }
+}
+
+.content {
+ display: block;
+}
+
+.timestamp {
+ color: $grayLight;
+}
+
+aside {
+ textarea {
+ height: 100px;
+ margin-bottom: 5px;
+ }
+}
diff --git a/app/assets/stylesheets/sessions.css.scss b/app/assets/stylesheets/sessions.css.scss
new file mode 100644
index 000000000..ccb1ed25b
--- /dev/null
+++ b/app/assets/stylesheets/sessions.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the Sessions controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/assets/stylesheets/static_pages.css.scss b/app/assets/stylesheets/static_pages.css.scss
new file mode 100644
index 000000000..d55836c3c
--- /dev/null
+++ b/app/assets/stylesheets/static_pages.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the StaticPages controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/assets/stylesheets/users.css.scss b/app/assets/stylesheets/users.css.scss
new file mode 100644
index 000000000..31a2eacb8
--- /dev/null
+++ b/app/assets/stylesheets/users.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the Users controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index e8065d950..6d4bf3c1e 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -1,3 +1,4 @@
class ApplicationController < ActionController::Base
protect_from_forgery
+ include SessionsHelper
end
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb
new file mode 100644
index 000000000..a45ef1dd3
--- /dev/null
+++ b/app/controllers/sessions_controller.rb
@@ -0,0 +1,21 @@
+class SessionsController < ApplicationController
+
+ def new
+ end
+
+ def create
+ user = User.find_by_email(params[:session][:email])
+ if user && user.authenticate(params[:session][:password])
+ sign_in user
+ redirect_back_or user
+ else
+ flash.now[:error] = 'Invalid email/password combination'
+ render 'new'
+ end
+ end
+
+ def destroy
+ sign_out
+ redirect_to root_url
+ end
+end
\ No newline at end of file
diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb
new file mode 100644
index 000000000..c0a7151e1
--- /dev/null
+++ b/app/controllers/static_pages_controller.rb
@@ -0,0 +1,17 @@
+class StaticPagesController < ApplicationController
+
+ def home
+ if signed_in?
+ # current_user is reference to the current user... use it to ask stuff about the user and show something
+ end
+ end
+
+ def help
+ end
+
+ def about
+ end
+
+ def contact
+ end
+end
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
new file mode 100644
index 000000000..83bb97884
--- /dev/null
+++ b/app/controllers/users_controller.rb
@@ -0,0 +1,74 @@
+class UsersController < ApplicationController
+ before_filter :signed_in_user,
+ only: [:index, :edit, :update, :destroy, :following, :followers]
+ before_filter :correct_user, only: [:edit, :update]
+ before_filter :admin_user, only: :destroy
+
+ def index
+ @users = User.paginate(page: params[:page])
+ end
+
+ def show
+ @user = User.find(params[:id])
+ @microposts = @user.microposts.paginate(page: params[:page])
+ end
+
+ def new
+ @user = User.new
+ end
+
+ def create
+ @user = User.new(params[:user])
+ if @user.save
+ sign_in @user
+ flash[:success] = "Welcome to the Sample App!"
+ redirect_to @user
+ else
+ render 'new'
+ end
+ end
+
+ def edit
+ end
+
+ def update
+ if @user.update_attributes(params[:user])
+ flash[:success] = "Profile updated"
+ sign_in @user
+ redirect_to @user
+ else
+ render 'edit'
+ end
+ end
+
+ def destroy
+ User.find(params[:id]).destroy
+ flash[:success] = "User destroyed."
+ redirect_to users_url
+ end
+
+ def following
+ @title = "Following"
+ @user = User.find(params[:id])
+ @users = @user.followed_users.paginate(page: params[:page])
+ render 'show_follow'
+ end
+
+ def followers
+ @title = "Followers"
+ @user = User.find(params[:id])
+ @users = @user.followers.paginate(page: params[:page])
+ render 'show_follow'
+ end
+
+ private
+
+ def correct_user
+ @user = User.find(params[:id])
+ redirect_to(root_url) unless current_user?(@user)
+ end
+
+ def admin_user
+ redirect_to(root_url) unless current_user.admin?
+ end
+end
\ No newline at end of file
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index de6be7945..49b0dace0 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1,2 +1,12 @@
module ApplicationHelper
+
+ # Returns the full title on a per-page basis.
+ def full_title(page_title)
+ base_title = "Ruby on Rails Tutorial Sample App"
+ if page_title.empty?
+ base_title
+ else
+ "#{base_title} | #{page_title}"
+ end
+ end
end
diff --git a/app/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb
new file mode 100644
index 000000000..3625479c7
--- /dev/null
+++ b/app/helpers/sessions_helper.rb
@@ -0,0 +1,44 @@
+module SessionsHelper
+
+ def sign_in(user)
+ cookies.permanent[:remember_token] = user.remember_token
+ self.current_user = user
+ end
+
+ def signed_in?
+ !current_user.nil?
+ end
+
+ def current_user=(user)
+ @current_user = user
+ end
+
+ def current_user
+ @current_user ||= User.find_by_remember_token(cookies[:remember_token])
+ end
+
+ def current_user?(user)
+ user == current_user
+ end
+
+ def signed_in_user
+ unless signed_in?
+ store_location
+ redirect_to signin_url, notice: "Please sign in."
+ end
+ end
+
+ def sign_out
+ current_user = nil
+ cookies.delete(:remember_token)
+ end
+
+ def redirect_back_or(default)
+ redirect_to(session[:return_to] || default)
+ session.delete(:return_to)
+ end
+
+ def store_location
+ session[:return_to] = request.url
+ end
+end
diff --git a/app/helpers/static_pages_helper.rb b/app/helpers/static_pages_helper.rb
new file mode 100644
index 000000000..2d63e79e6
--- /dev/null
+++ b/app/helpers/static_pages_helper.rb
@@ -0,0 +1,2 @@
+module StaticPagesHelper
+end
diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb
new file mode 100644
index 000000000..c27d31cbb
--- /dev/null
+++ b/app/helpers/users_helper.rb
@@ -0,0 +1,11 @@
+module UsersHelper
+
+ # Returns the Gravatar (http://gravatar.com/) for the given user.
+ def gravatar_for(user, options = { size: 50 })
+ gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
+ size = options[:size]
+ gravatar =
+ gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{size}"
+ image_tag(gravatar_url, alt: user.name, class: "gravatar")
+ end
+end
diff --git a/app/models/relationship.rb b/app/models/relationship.rb
new file mode 100644
index 000000000..d644bb8b3
--- /dev/null
+++ b/app/models/relationship.rb
@@ -0,0 +1,9 @@
+class Relationship < ActiveRecord::Base
+ attr_accessible :followed_id
+
+ belongs_to :follower, class_name: "User"
+ belongs_to :followed, class_name: "User"
+
+ validates :follower_id, presence: true
+ validates :followed_id, presence: true
+end
diff --git a/app/models/user.rb b/app/models/user.rb
new file mode 100644
index 000000000..30bad85b0
--- /dev/null
+++ b/app/models/user.rb
@@ -0,0 +1,43 @@
+class User < ActiveRecord::Base
+ attr_accessible :name, :email, :password, :password_confirmation
+ has_secure_password
+ has_many :microposts, dependent: :destroy
+ has_many :relationships, foreign_key: "follower_id", dependent: :destroy
+ has_many :followed_users, through: :relationships, source: :followed
+ has_many :reverse_relationships, foreign_key: "followed_id",
+ class_name: "Relationship",
+ dependent: :destroy
+ has_many :followers, through: :reverse_relationships, source: :follower
+
+ before_save { |user| user.email = email.downcase }
+ before_save :create_remember_token
+
+ validates :name, presence: true, length: { maximum: 50 }
+ VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
+ validates :email, presence: true, format: { with: VALID_EMAIL_REGEX },
+ uniqueness: { case_sensitive: false }
+ validates :password, length: { minimum: 6 }
+ validates :password_confirmation, presence: true
+
+ def feed
+ Micropost.from_users_followed_by(self)
+ end
+
+ def following?(other_user)
+ relationships.find_by_followed_id(other_user.id)
+ end
+
+ def follow!(other_user)
+ relationships.create!(followed_id: other_user.id)
+ end
+
+ def unfollow!(other_user)
+ relationships.find_by_followed_id(other_user.id).destroy
+ end
+
+ private
+
+ def create_remember_token
+ self.remember_token = SecureRandom.urlsafe_base64
+ end
+end
diff --git a/app/views/layouts/_footer.html.erb b/app/views/layouts/_footer.html.erb
new file mode 100644
index 000000000..079c29c49
--- /dev/null
+++ b/app/views/layouts/_footer.html.erb
@@ -0,0 +1,13 @@
+
diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb
new file mode 100644
index 000000000..56df8e465
--- /dev/null
+++ b/app/views/layouts/_header.html.erb
@@ -0,0 +1,32 @@
+
+
+