Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: xmonkey/railstutors_project
base: 976b0e10a6
...
head fork: xmonkey/railstutors_project
compare: f2f1efb9e4
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 22 files changed
  • 0 commit comments
  • 1 contributor
Commits on Dec 18, 2012
@xmonkey Build the user profile page e29acd8
Commits on Dec 19, 2012
@xmonkey Add node to post. f2f1efb
View
1  Gemfile
@@ -2,6 +2,7 @@ source 'https://rubygems.org'
gem 'rails', '3.2.3'
gem 'bootstrap-sass'
+gem 'twitter'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
View
9 Gemfile.lock
@@ -42,6 +42,8 @@ GEM
erubis (2.7.0)
execjs (1.4.0)
multi_json (~> 1.0)
+ faraday (0.8.4)
+ multipart-post (~> 1.1)
hike (1.2.1)
i18n (0.6.1)
journey (1.0.4)
@@ -55,6 +57,7 @@ GEM
treetop (~> 1.4.8)
mime-types (1.19)
multi_json (1.3.6)
+ multipart-post (1.1.5)
pg (0.14.1)
polyglot (0.3.3)
rack (1.4.1)
@@ -87,6 +90,7 @@ GEM
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
+ simple_oauth (0.2.0)
sprockets (2.1.3)
hike (~> 1.2)
rack (~> 1.0)
@@ -97,6 +101,10 @@ GEM
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
+ twitter (4.4.1)
+ faraday (~> 0.8)
+ multi_json (~> 1.3)
+ simple_oauth (~> 0.2)
tzinfo (0.3.33)
uglifier (1.3.0)
execjs (>= 0.3.0)
@@ -114,4 +122,5 @@ DEPENDENCIES
rails (= 3.2.3)
sass-rails (~> 3.2.3)
sqlite3
+ twitter
uglifier (>= 1.0.3)
View
7 app/controllers/nodes_controller.rb
@@ -0,0 +1,7 @@
+class NodesController < ApplicationController
+ def show
+ @node = Node.find(params[:id])
+ @posts = @node.posts
+ render "posts/index"
+ end
+end
View
2  app/controllers/posts_controller.rb
@@ -13,7 +13,7 @@ def new
end
def create
- @post = Post.create(params[:post])
+ @post = Post.new(params[:post])
@post.user = current_user
if @post.save
redirect_to posts_path
View
9 app/controllers/users_controller.rb
@@ -4,7 +4,7 @@ def new
end
def create
- @user = User.create(params[:user])
+ @user = User.build(params[:user])
if @user.save
session[:user] = @user
redirect_to root_path, :notice => "User #{@user.name} was created!"
@@ -12,4 +12,11 @@ def create
render :new
end
end
+
+ def show
+ @user = User.find(params[:id])
+ @comments = @user.recent(@user.comments)
+ @posts = @user.recent(@user.posts)
+ @votes = @user.recent(@user.votes)
+ end
end
View
5 app/controllers/votes_controller.rb
@@ -1,7 +1,10 @@
class VotesController < ApplicationController
def create
@post = Post.find(params[:post_id])
- @vote = @post.votes.create(params[:vote])
+ vote = @post.votes.new()
+ vote.upvote = params[:upvote]
+ vote.user_id = current_user.try :id
+ vote.save
redirect_to posts_path
end
end
View
4 app/models/node.rb
@@ -0,0 +1,4 @@
+class Node < ActiveRecord::Base
+ attr_accessible :name
+ has_many :posts
+end
View
12 app/models/post.rb
@@ -2,10 +2,20 @@ class Post < ActiveRecord::Base
has_many :comments
has_many :votes
belongs_to :user
- attr_accessible :title, :url
+ belongs_to :node
+ attr_accessible :title, :url, :node_name
validates :title, :presence => true
validates :url, :presence => true
def votes_count
votes.where(:upvote => true).count - votes.where(:upvote => false).count
end
+
+ def node_name
+ node.name if self.node
+ end
+
+ def node_name=(name)
+ self.node =Node.find_or_create_by_name(name) unless name.blank?
+ end
+
end
View
10 app/models/user.rb
@@ -1,5 +1,13 @@
class User < ActiveRecord::Base
- attr_accessible :name, :password_digest, :password
+ attr_accessible :name, :password
has_secure_password
validates :name, :uniqueness => true, :presence => true
+ has_many :posts
+ has_many :comments
+ has_many :votes
+
+ def recent(activities)
+ activities.order("created_at DESC").limit(5)
+ end
+
end
View
1  app/models/vote.rb
@@ -1,4 +1,5 @@
class Vote < ActiveRecord::Base
belongs_to :post
+ belongs_to :user
attr_accessible :upvote
end
View
4 app/views/posts/index.html.erb
@@ -5,9 +5,9 @@
by <%= post.user.name %>
<%= link_to pluralize(post.comments.count, ' comment'), post %>
<%= pluralize(post.votes_count, ' vote' )%>
- <%= link_to "upvote", post_votes_path(post, :vote => [:upvote =>true]), :method => :post %>
+ <%= link_to "upvote", post_votes_path(post, upvote: true ), :method => :post %>
|
- <%= link_to "downvote", post_votes_path(post, :vote => [:upvote =>false]), :method => :post %>
+ <%= link_to "downvote", post_votes_path(post, upvote: false), :method => :post %>
</p>
<% end %>
View
4 app/views/posts/new.html.erb
@@ -17,6 +17,10 @@
<%= f.label :url %><br />
<%= f.text_field :url %>
</div>
+ <div class="field">
+ <%= f.label :node_name %><br />
+ <%= f.text_field :node_name %>
+ </div>
<div class="actions">
<%= f.submit %>
</div>
View
6 app/views/posts/show.html.erb
@@ -1,5 +1,11 @@
<h3><%= link_to @post.title, url_link(@post) %> </h3>
+<% unless @post.node_name.blank? %>
+ node: <%= link_to @post.node_name, @post.node %>
+<% end %>
+
+
<p><%= pluralize(@post.comments.count, ' comment') %> </p>
+
<ul>
<% @post.comments.each do |comment| %>
<li>
View
41 app/views/users/show.html.erb
@@ -0,0 +1,41 @@
+<h2> User Profile </h2>
+
+<ul>
+ <li>
+ name: <%= @user.name %>
+ </li>
+ <li>
+ Joined on: <%= @user.created_at.to_date.to_s %>
+ </li>
+</ul>
+
+<h3>Recent Activities:</h3>
+Posts:
+<ul>
+ <% @posts.each do |post| %>
+ <li>
+ <%= link_to post.title, url_link(post) %>
+ </li>
+ <% end %>
+</ul>
+Comments:
+<ul>
+ <% @comments.each do |comment| %>
+ <li>
+ <%= comment.content %>
+ </li>
+ <% end %>
+</ul>
+Votes:
+<ul>
+ <% @votes.each do |vote| %>
+ <li>
+ <% if vote.upvote %>
+ Upvoted:
+ <% else %>
+ Downvoted
+ <% end %>
+ :<%= link_to vote.post.title, url_link(vote.post) %>
+ </li>
+ <% end %>
+</ul>
View
4 config/routes.rb
@@ -1,6 +1,6 @@
CourseProject::Application.routes.draw do
get 'sign_up', to: "users#new", :as => :sign_up
- resources :users, :only => :create
+ resources :users, :only => [:create, :show]
get 'sign_in', to: "sessions#new", :as => :sign_in
post 'sign_in', to: "sessions#create"
@@ -12,4 +12,6 @@
resources :comments, :only => :create
resources :votes, :only => :create
end
+
+ resources :nodes, :only => :show
end
View
5 db/migrate/20121218131337_add_user_to_votes.rb
@@ -0,0 +1,5 @@
+class AddUserToVotes < ActiveRecord::Migration
+ def change
+ add_column :votes, :user_id, :integer
+ end
+end
View
5 db/migrate/20121218140444_add_twitter_to_user.rb
@@ -0,0 +1,5 @@
+class AddTwitterToUser < ActiveRecord::Migration
+ def change
+ add_column :users, :twitter, :string
+ end
+end
View
9 db/migrate/20121218140844_create_nodes.rb
@@ -0,0 +1,9 @@
+class CreateNodes < ActiveRecord::Migration
+ def change
+ create_table :nodes do |t|
+ t.string :name
+
+ t.timestamps
+ end
+ end
+end
View
5 db/migrate/20121218141949_add_node_to_post.rb
@@ -0,0 +1,5 @@
+class AddNodeToPost < ActiveRecord::Migration
+ def change
+ add_column :posts, :node_id, :integer
+ end
+end
View
11 db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20121214094120) do
+ActiveRecord::Schema.define(:version => 20121218141949) do
create_table "comments", :force => true do |t|
t.text "content"
@@ -23,12 +23,19 @@
add_index "comments", ["post_id"], :name => "index_comments_on_post_id"
+ create_table "nodes", :force => true do |t|
+ t.string "name"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
create_table "posts", :force => true do |t|
t.string "url"
t.string "title"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "user_id"
+ t.integer "node_id"
end
create_table "users", :force => true do |t|
@@ -36,6 +43,7 @@
t.string "name"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
+ t.string "twitter"
end
create_table "votes", :force => true do |t|
@@ -43,6 +51,7 @@
t.integer "post_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
+ t.integer "user_id"
end
add_index "votes", ["post_id", "upvote"], :name => "index_votes_on_post_id_and_upvote"
View
7 test/fixtures/nodes.yml
@@ -0,0 +1,7 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ name: MyString
+
+two:
+ name: MyString
View
7 test/unit/node_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class NodeTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end

No commit comments for this range

Something went wrong with that request. Please try again.