Permalink
Browse files

Add user following

  • Loading branch information...
1 parent 15794ce commit 2263d597d3a8adfb47b0b4e360f9f3e864aac8f0 @perfectionist committed Jul 17, 2012
View
@@ -1,7 +1,7 @@
source 'https://rubygems.org'
-ruby '1.9.3'
-gem 'rails', '3.2.3'
+# ruby '1.9.3'
+gem 'rails', '3.2.5'
gem 'bootstrap-sass', '2.0.0'
gem 'pg', '0.12.2'
gem 'bcrypt-ruby', '3.0.1'
View
@@ -1,33 +1,34 @@
GEM
remote: https://rubygems.org/
specs:
- actionmailer (3.2.3)
- actionpack (= 3.2.3)
+ actionmailer (3.2.5)
+ actionpack (= 3.2.5)
mail (~> 2.4.4)
- actionpack (3.2.3)
- activemodel (= 3.2.3)
- activesupport (= 3.2.3)
+ actionpack (3.2.5)
+ activemodel (= 3.2.5)
+ activesupport (= 3.2.5)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.1)
rack (~> 1.4.0)
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
- sprockets (~> 2.1.2)
- activemodel (3.2.3)
- activesupport (= 3.2.3)
+ sprockets (~> 2.1.3)
+ activemodel (3.2.5)
+ activesupport (= 3.2.5)
builder (~> 3.0.0)
- activerecord (3.2.3)
- activemodel (= 3.2.3)
- activesupport (= 3.2.3)
+ activerecord (3.2.5)
+ activemodel (= 3.2.5)
+ activesupport (= 3.2.5)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
- activeresource (3.2.3)
- activemodel (= 3.2.3)
- activesupport (= 3.2.3)
- activesupport (3.2.3)
+ activeresource (3.2.5)
+ activemodel (= 3.2.5)
+ activesupport (= 3.2.5)
+ activesupport (3.2.5)
i18n (~> 0.6)
multi_json (~> 1.0)
+ addressable (2.2.8)
annotate (2.4.1.beta1)
arel (3.0.2)
bcrypt-ruby (3.0.1)
@@ -42,19 +43,19 @@ GEM
rack-test (>= 0.5.4)
selenium-webdriver (~> 2.0)
xpath (~> 0.1.4)
- childprocess (0.3.1)
+ childprocess (0.3.2)
ffi (~> 1.0.6)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
coffee-script (2.2.0)
coffee-script-source
execjs
- coffee-script-source (1.3.1)
- cucumber (1.2.0)
+ coffee-script-source (1.3.3)
+ cucumber (1.2.1)
builder (>= 2.1.2)
diff-lcs (>= 1.1.3)
- gherkin (~> 2.10.0)
+ gherkin (~> 2.11.0)
json (>= 1.4.6)
cucumber-rails (1.2.1)
capybara (>= 1.1.2)
@@ -63,7 +64,7 @@ GEM
database_cleaner (0.7.0)
diff-lcs (1.1.3)
erubis (2.7.0)
- execjs (1.3.0)
+ execjs (1.4.0)
multi_json (~> 1.0)
factory_girl (2.3.2)
activesupport
@@ -73,10 +74,10 @@ GEM
faker (1.0.1)
i18n (~> 0.4)
ffi (1.0.11)
- gherkin (2.10.0)
+ gherkin (2.11.0)
json (>= 1.4.6)
- guard (1.0.3)
- ffi (>= 0.5.0)
+ guard (1.1.1)
+ listen (>= 0.4.2)
thor (>= 0.14.6)
guard-rspec (0.5.5)
guard (>= 0.8.4)
@@ -89,14 +90,20 @@ GEM
jquery-rails (2.0.0)
railties (>= 3.2.0.beta, < 5.0)
thor (~> 0.14)
- json (1.6.6)
+ json (1.7.3)
+ libwebsocket (0.1.3)
+ addressable
+ listen (0.4.4)
+ rb-fchange (~> 0.0.5)
+ rb-fsevent (~> 0.9.1)
+ rb-inotify (~> 0.8.8)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.18)
- multi_json (1.2.0)
- nokogiri (1.5.2)
+ multi_json (1.3.6)
+ nokogiri (1.5.4)
pg (0.12.2)
polyglot (0.3.3)
rack (1.4.1)
@@ -106,22 +113,27 @@ GEM
rack
rack-test (0.6.1)
rack (>= 1.0)
- rails (3.2.3)
- actionmailer (= 3.2.3)
- actionpack (= 3.2.3)
- activerecord (= 3.2.3)
- activeresource (= 3.2.3)
- activesupport (= 3.2.3)
+ rails (3.2.5)
+ actionmailer (= 3.2.5)
+ actionpack (= 3.2.5)
+ activerecord (= 3.2.5)
+ activeresource (= 3.2.5)
+ activesupport (= 3.2.5)
bundler (~> 1.0)
- railties (= 3.2.3)
- railties (3.2.3)
- actionpack (= 3.2.3)
- activesupport (= 3.2.3)
+ railties (= 3.2.5)
+ railties (3.2.5)
+ actionpack (= 3.2.5)
+ activesupport (= 3.2.5)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
- thor (~> 0.14.6)
+ thor (>= 0.14.6, < 2.0)
rake (0.9.2.2)
+ rb-fchange (0.0.5)
+ ffi
+ rb-fsevent (0.9.1)
+ rb-inotify (0.8.8)
+ ffi (>= 0.5.0)
rdoc (3.12)
json (~> 1.4)
rspec (2.10.0)
@@ -137,23 +149,24 @@ GEM
activesupport (>= 3.0)
railties (>= 3.0)
rspec (~> 2.10.0)
- rubyzip (0.9.7)
- sass (3.1.15)
+ rubyzip (0.9.8)
+ sass (3.1.19)
sass-rails (3.2.4)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
- selenium-webdriver (2.20.0)
+ selenium-webdriver (2.22.2)
childprocess (>= 0.2.5)
ffi (~> 1.0)
+ libwebsocket (~> 0.1.3)
multi_json (~> 1.0)
rubyzip
spork (0.9.0)
- sprockets (2.1.2)
+ sprockets (2.1.3)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
- thor (0.14.6)
+ thor (0.15.2)
tilt (1.3.3)
treetop (1.4.10)
polyglot
@@ -184,7 +197,7 @@ DEPENDENCIES
guard-spork (= 0.3.2)
jquery-rails (= 2.0.0)
pg (= 0.12.2)
- rails (= 3.2.3)
+ rails (= 3.2.5)
rspec-rails (= 2.10.0)
sass-rails (= 3.2.4)
spork (= 0.9.0)
View
@@ -4,7 +4,24 @@ This is the sample application for
[*Ruby on Rails Tutorial: Learn Rails by Example*](http://railstutorial.org)
by [Michael Hartl](http://michaelhartl.com).
-I am using [RubyMine](http://www.jetbrains.com/ruby/)
+I am using [RubyMine]
instead of [Sublime Text 2](http://www.sublimetext.com/2)
as my editor/IDE. Check out tips on using RubyMine in this project's
[wiki](https://github.com/perfectionist/sample_project/wiki)
+
+For editing Markdown there are a number of options. Just go to Mac App Store and search
+for **[markdown]**. **[Mou]** is not at the MAS but is availiable
+and is free. I personally like a combination of **[Multimarkdown Composer]** and **[Marked]**
+ and both are available from the MAS. **[Marked]** is just a previewer and
+ works with any editor, plus it has a
+ **[GitHub]** style for previewing. **Multimarkdown Composer** handles both Markdown and
+ Multimarkdown syntax. GitHub's syntax is in between but closer to [Multimarkdown].
+ There is even a **[Markdown]** plugin for [RubyMine] which I am using for editing
+ this `README.md` file.
+
+ [RubyMine]:http://www.jetbrains.com/ruby/
+ [Markdown]:http://daringfireball.net/projects/markdown/
+ [Multimarkdown Composer]:http://multimarkdown.com/
+ [Marked]:http://markedapp.com/
+ [GitHub]:http://www.github.com/
+ [Mou]:http://mouapp.com/
@@ -149,6 +149,34 @@ aside {
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;
+ .gravator {
+ margin: 1px 1px;
+ }
+}
/* forms */
input, textarea, select, .uneditable-input {
@@ -0,0 +1,21 @@
+class RelationshipsController < ApplicationController
+ before_filter :signed_in_user
+
+ def create
+ @user = User.find(params[:relationship][:followed_id])
+ current_user.follow!(@user)
+ respond_to do |format|
+ format.html { redirect_to @user }
+ format.js
+ end
+ end
+
+ def destroy
+ @user = Relationship.find(params[:id]).followed
+ current_user.unfollow!(@user)
+ respond_to do |format|
+ format.html { redirect_to @user }
+ format.js
+ end
+ end
+end
@@ -1,5 +1,5 @@
class UsersController < ApplicationController
- before_filter :signed_in_user, only: [:index, :edit, :update, :destroy]
+ 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]
@@ -48,6 +48,20 @@ def destroy
redirect_to users_path
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
View
@@ -1,12 +1,3 @@
-class Micropost < ActiveRecord::Base
- attr_accessible :content
- belongs_to :user
-
- validates :content, presence: true, length: { maximum: 140 }
- validates :user_id, presence: true
-
- default_scope order: 'microposts.created_at DESC'
-end
# == Schema Information
#
# Table name: microposts
@@ -17,4 +8,22 @@ class Micropost < ActiveRecord::Base
# created_at :datetime not null
# updated_at :datetime not null
#
+# Indexes
+#
+# index_microposts_on_user_id_and_created_at (user_id,created_at)
+#
+class Micropost < ActiveRecord::Base
+ attr_accessible :content
+ belongs_to :user
+
+ validates :content, presence: true, length: { maximum: 140 }
+ validates :user_id, presence: true
+
+ default_scope order: 'microposts.created_at DESC'
+
+ def self.from_users_followed_by(user)
+ followed_user_ids = "SELECT followed_id FROM relationships WHERE follower_id = :user_id"
+ where("user_id IN (#{followed_user_ids}) OR user_id = :user_id", user_id: user.id)
+ end
+end
View
@@ -0,0 +1,26 @@
+# == Schema Information
+#
+# Table name: relationships
+#
+# id :integer not null, primary key
+# follower_id :integer
+# followed_id :integer
+# created_at :datetime not null
+# updated_at :datetime not null
+#
+# Indexes
+#
+# index_relationships_on_followed_id (followed_id)
+# index_relationships_on_follower_id (follower_id)
+# index_relationships_on_follower_id_and_followed_id (follower_id,followed_id) UNIQUE
+#
+
+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
Oops, something went wrong.

0 comments on commit 2263d59

Please sign in to comment.