Permalink
Browse files

added twitter bootstrap and the ability to follow a user

  • Loading branch information...
1 parent d5abf29 commit 57a740c6a6426ede42376446158a315095df676c @drapergeek committed Mar 13, 2012
View
1 Gemfile
@@ -14,6 +14,7 @@ end
gem 'jquery-rails'
gem 'paperclip'
+gem "twitter-bootstrap-rails"
group :test do
gem 'rspec-rails'
View
16 Gemfile.lock
@@ -43,6 +43,8 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.2.0)
+ commonjs (0.2.0)
+ therubyracer (~> 0.9.9)
diesel (0.1.5)
railties
diff-lcs (1.1.3)
@@ -61,6 +63,13 @@ GEM
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
json (1.6.5)
+ less (2.0.10)
+ commonjs (~> 0.2.0)
+ therubyracer (~> 0.9.9)
+ less-rails (2.1.7)
+ actionpack (>= 3.1)
+ less (~> 2.0.7)
+ libv8 (3.3.10.4)
mail (2.4.3)
i18n (>= 0.4.0)
mime-types (~> 1.16)
@@ -123,11 +132,17 @@ GEM
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.5)
+ therubyracer (0.9.10)
+ libv8 (~> 3.3.10)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
+ twitter-bootstrap-rails (2.0.3)
+ actionpack (>= 3.1)
+ less-rails (~> 2.1.6)
+ railties (>= 3.1)
tzinfo (0.3.32)
uglifier (1.2.3)
execjs (>= 0.3.0)
@@ -147,4 +162,5 @@ DEPENDENCIES
rspec-rails
sass-rails (~> 3.2.3)
sqlite3
+ twitter-bootstrap-rails
uglifier (>= 1.0.3)
View
1 app/assets/javascripts/application.js
@@ -12,4 +12,5 @@
//
//= require jquery
//= require jquery_ujs
+//= require twitter/bootstrap
//= require_tree .
View
4 app/assets/javascripts/bootstrap.js.coffee
@@ -0,0 +1,4 @@
+jQuery ->
+ $("a[rel=popover]").popover()
+ $(".tooltip").tooltip()
+ $("a[rel=tooltip]").tooltip()
View
3 app/assets/javascripts/follows.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/
View
1 app/assets/stylesheets/application.css
@@ -11,3 +11,4 @@
*= require_self
*= require_tree .
*/
+body { padding-top: 60px; }
View
17 app/assets/stylesheets/bootstrap_and_overrides.css.less
@@ -0,0 +1,17 @@
+@import "twitter/bootstrap/bootstrap";
+@import "twitter/bootstrap/responsive";
+
+// Set the correct sprite paths
+@iconSpritePath: asset-path('twitter/bootstrap/glyphicons-halflings.png');
+@iconWhiteSpritePath: asset-path('twitter/bootstrap/glyphicons-halflings-white.png');
+
+// Your custom LESS stylesheets goes here
+//
+// Since bootstrap was imported above you have access to its mixins which
+// you may use and inherit here
+//
+// If you'd like to override bootstrap's own variables, you can do so here as well
+// See http://twitter.github.com/bootstrap/less.html for their names and documentation
+//
+// Example:
+// @linkColor: #ff0000;
View
3 app/assets/stylesheets/follows.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the Follows controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
8 app/controllers/following_relationships_controller.rb
@@ -0,0 +1,8 @@
+class FollowingRelationshipsController < ApplicationController
+
+ def create
+ user = User.find(params[:user_id])
+ current_user.follow(user)
+ redirect_to user, notice: "Now following"
+ end
+end
View
1 app/controllers/users_controller.rb
@@ -3,5 +3,6 @@ class UsersController < ApplicationController
def show
@user = User.find(params[:id])
@shouts = @user.shouts.current
+ @following_relationship = FollowingRelationship.new(:followed_user_id=>@user.id)
end
end
View
2 app/helpers/follows_helper.rb
@@ -0,0 +1,2 @@
+module FollowsHelper
+end
View
5 app/helpers/users_helper.rb
@@ -0,0 +1,5 @@
+module UsersHelper
+ def can_follow(user)
+ current_user != user && !current_user.followed_users.include?(user)
+ end
+end
View
4 app/models/following_relationship.rb
@@ -0,0 +1,4 @@
+class FollowingRelationship < ActiveRecord::Base
+ belongs_to :following_user, :class_name=>"User"
+ belongs_to :followed_user, :class_name=>"User"
+end
View
8 app/models/user.rb
@@ -2,8 +2,16 @@ class User < ActiveRecord::Base
include Clearance::User
has_many :shouts
+ has_many :following_relationships, foreign_key: "following_user_id"
+ has_many :followed_users, through: :following_relationships
+
+
def create_shout(medium)
new_shout = shouts.create(medium: medium)
end
+ def follow(followed_user)
+ following_relationships.create(followed_user: followed_user)
+ end
+
end
View
2 app/views/dashboards/show.html.erb
@@ -1,5 +1,5 @@
<h1>Dashboard</h1>
-Welcome <%= current_user.email %>! <%= link_to "Sign Out", sign_out_path, method: :delete %>
+<p>Welcome <%= current_user.email %>! <%= link_to "Sign Out", sign_out_path, method: :delete %></p>
<%= form_for @text_shout do |f| %>
<%= f.text_field :body, placeholder: "Shout here" %>
<%= f.submit "Shout!" %>
View
27 app/views/layouts/application.html.erb
@@ -7,10 +7,31 @@
<%= csrf_meta_tags %>
</head>
<body>
+ <div class="navbar navbar-fixed-top">
+ <div class="navbar-inner">
+ <div class="container">
+ <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
+ <span class="icon-bar"></span>
+ <span class="icon-bar"></span>
+ <span class="icon-bar"></span>
+ </a>
+ <%= link_to "Shouter",root_url, :class=>"brand" %>
+ <div class="nav-collapse">
+ <ul class="nav">
+ </ul>
+ </div>
+ </div>
+ </div>
+ </div>
+
<div class="content">
- <% flash.each do |key, value| -%>
- <div class="flash <%= key %>"><%= value %></div>
- <% end -%>
+ <% flash.each do |name, msg| %>
+ <div class="alert alert-<%= name == :notice ? "success" : "error" %>">
+ <a class="close" data-dismiss="alert">×</a>
+ <%= msg %>
+ </div>
+ <% end %>
+
<%= yield %>
</div>
View
3 app/views/users/show.html.erb
@@ -1,4 +1,7 @@
<h1><%= @user.email %></h1>
<div id="shouts">
<%= render @shouts %>
+ <% if can_follow @user %>
+ <%= button_to "Follow", user_following_relationships_path(@user), class: "btn btn-warning" %>
+ <% end %>
</div>
View
5 config/routes.rb
@@ -3,6 +3,9 @@
resources :shouts, only: [:show]
resources :text_shouts, only: [:create]
resources :photo_shouts, only: [:create]
- resources :users, only: [:show]
+ resources :users, only: [:show] do
+ resources :following_relationships, only: [:create]
+ end
+
root to: "welcome#index"
end
View
12 db/migrate/20120313140652_create_following_relationships.rb
@@ -0,0 +1,12 @@
+class CreateFollowingRelationships < ActiveRecord::Migration
+ def change
+ create_table :following_relationships do |t|
+ t.belongs_to :following_user
+ t.belongs_to :followed_user
+
+ t.timestamps
+ end
+ add_index :following_relationships, :following_user_id
+ add_index :following_relationships, :followed_user_id
+ end
+end
View
12 db/schema.rb
@@ -11,7 +11,17 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120312184732) do
+ActiveRecord::Schema.define(:version => 20120313140652) do
+
+ create_table "following_relationships", :force => true do |t|
+ t.integer "following_user_id"
+ t.integer "followed_user_id"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+ add_index "following_relationships", ["followed_user_id"], :name => "index_following_relationships_on_followed_user_id"
+ add_index "following_relationships", ["following_user_id"], :name => "index_following_relationships_on_following_user_id"
create_table "photo_shouts", :force => true do |t|
t.datetime "created_at", :null => false
View
7 spec/models/user_spec.rb
@@ -9,4 +9,11 @@
shout.persisted?.should == true
text_shout.persisted?.should == true
end
+
+ it "can #follow other users" do
+ follower = create(:user)
+ followed_user = create(:user)
+ follower.follow(followed_user)
+ follower.followed_users.should == [followed_user]
+ end
end
View
9 test/fixtures/following_relationships.yml
@@ -0,0 +1,9 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ following_user:
+ followed_user:
+
+two:
+ following_user:
+ followed_user:
View
7 test/functional/follows_controller_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class FollowsControllerTest < ActionController::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
View
7 test/unit/following_relationship_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class FollowingRelationshipTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
View
4 test/unit/helpers/follows_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class FollowsHelperTest < ActionView::TestCase
+end

0 comments on commit 57a740c

Please sign in to comment.