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: RubySchools/social_network
base: a3ef90e3f4
...
head fork: RubySchools/social_network
compare: 463e19a045
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 29 files changed
  • 0 commit comments
  • 1 contributor
Showing with 176 additions and 132 deletions.
  1. +1 −1  Gemfile
  2. +2 −0  Gemfile.lock
  3. +3 −0  app/assets/javascripts/message.js.coffee
  4. +3 −0  app/assets/stylesheets/message.css.scss
  5. +37 −0 app/controllers/messages_controller.rb
  6. +1 −1  app/controllers/uploads_controller.rb
  7. +2 −0  app/helpers/message_helper.rb
  8. +9 −0 app/models/message.rb
  9. +10 −0 app/models/message_recipient.rb
  10. +0 −8 app/models/post.rb.save
  11. +5 −4 app/models/user.rb
  12. +9 −6 app/views/layouts/_header.html.erb
  13. +9 −0 app/views/layouts/{_stylesheets.html.erb → _style_and_meta.html.erb}
  14. +3 −40 app/views/layouts/application.html.erb
  15. +6 −36 app/views/layouts/application.html.erb~
  16. +12 −0 app/views/messages/create.html.erb
  17. +7 −0 app/views/messages/index.html.erb
  18. +11 −0 app/views/messages/show.html.erb
  19. +0 −2  app/views/pages/home.html.erb
  20. +0 −17 app/views/pages/home.html.erb.save
  21. +1 −3 app/views/posts/_post.html.erb
  22. +0 −4 app/views/shared/_feed.html.erb.save
  23. +1 −1  app/views/uploads/index.html.erb
  24. +1 −2  app/views/users/index.html.erb
  25. +4 −4 app/views/users/show.html.erb
  26. +4 −2 config/routes.rb
  27. +10 −0 db/migrate/20120305154705_create_messages.rb
  28. +10 −0 db/migrate/20120305154753_create_messages_recipients.rb
  29. +15 −1 db/schema.rb
View
2  Gemfile
@@ -5,7 +5,7 @@ gem 'rails'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
-#gem 'sqlite3'
+gem 'sqlite3'
gem 'sorcery'
gem 'therubyracer', :platforms => [:ruby]
gem 'sorcery'
View
2  Gemfile.lock
@@ -134,6 +134,7 @@ GEM
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
+ sqlite3 (1.3.5)
term-ansicolor (1.0.7)
therubyracer (0.9.10)
libv8 (~> 3.3.10)
@@ -171,6 +172,7 @@ DEPENDENCIES
rspec
sass-rails (~> 3.2.3)
sorcery
+ sqlite3
therubyracer
thin
uglifier (>= 1.0.3)
View
3  app/assets/javascripts/message.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
3  app/assets/stylesheets/message.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the message controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
37 app/controllers/messages_controller.rb
@@ -0,0 +1,37 @@
+class MessagesController < ApplicationController
+
+def create
+ @recipient = User.find(params[:id])
+ @message = Message.new()
+ @message.content = params[:content]
+ @message.user = current_user
+ @message.save
+ mes_recipient = MessageRecipient.new()
+ mes_recipient.message_id = @message.id
+ mes_recipient.user_id = 1
+ mes_recipient.save
+end
+
+def show
+ @message = Message.find(params[:id])
+end
+
+def index
+ @messages = current_user.messages + current_user.recieved_messages
+end
+
+def update
+ @message = Message.find(params[:id])
+
+ respond_to do |format|
+ if @message.update_attributes(params[:message])
+ format.html { redirect_to @message, notice: 'message was successfully updated.' }
+ format.json { head :ok }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @message.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+end
View
2  app/controllers/uploads_controller.rb
@@ -39,7 +39,7 @@ def edit
# POST /files.json
def create
@file = Upload.new(params[:upload])
- @file.user = current_user
+ @file.user = current_user
respond_to do |format|
if @file.save
format.html { redirect_to(:uploads, :notice => 'file was successfully created.') }
View
2  app/helpers/message_helper.rb
@@ -0,0 +1,2 @@
+module MessageHelper
+end
View
9 app/models/message.rb
@@ -0,0 +1,9 @@
+class Message < ActiveRecord::Base
+#Relations
+ belongs_to :user
+ has_many :message_recipients
+ has_many :recipients, :through => :message_recipients, :source => :user
+#Validations
+ validate :user_id, :presence => true
+
+end
View
10 app/models/message_recipient.rb
@@ -0,0 +1,10 @@
+class MessageRecipient < ActiveRecord::Base
+#Relations
+ belongs_to :message
+ belongs_to :user
+
+#Validations
+ validate :user_id, :presence => true
+ validate :message_id , :presence => true
+
+end
View
8 app/models/post.rb.save
@@ -1,8 +0,0 @@
-lass Post < ActiveRecord::Base
- attr_accesible :content
- belongs_to :user
- validates :content, :presence => true, :length => { :maximum => 2000 }
- validates :user_id, :presence => true
- default_scope :order => 'posts.created_at DESC'
-
-end
View
9 app/models/user.rb
@@ -4,12 +4,13 @@ class User < ActiveRecord::Base
#Relations
has_many :uploads
-
has_many :users_upload
has_many :saved_uploads, :through => :users_upload, :source => :upload
-has_many :posts, :dependent => :destroy
-# has_many :uploads, :through => :users_uploads
-
+ has_many :posts, :dependent => :destroy
+
+ has_many :messages
+ has_many :message_recipient
+ has_many :recieved_messages, :through => :message_recipient, :source => :message
View
15 app/views/layouts/_header.html.erb
@@ -1,16 +1,19 @@
- <header>
- <%= image_tag("logo.png", :alt => "Ruby School", :class => "round") %>
+<header>
+ <%= image_tag("logo.png", :alt => "Ruby School", :class => "round") %>
<nav class="round">
<ul>
-
+ <li><%= link_to "Home", root_path %></li>
+ <li><%= link_to "Users", :userslist %></li>
<% if current_user %>
<li><%= link_to "Edit Profile", edit_user_path(current_user.id) %></li>
<li><%= link_to "Logout", :logout %></li>
- <li><%= link_to "my_downloads", :downloads %></li>
- <% else %>
+ <li><%= link_to "my_downloads", :my_downloads %></li>
+
+ <% else %>
<li><%= link_to "Register", new_user_path %></li>
<li><%= link_to "Login", :login %></li>
<% end %>
</ul>
- </nav>
+ </nav>
+
</header>
View
9 app/views/layouts/_stylesheets.html.erb → app/views/layouts/_style_and_meta.html.erb
@@ -1,3 +1,6 @@
+ <head>
+ <title>Social Network | <%= @title %></title>
+
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
@@ -5,3 +8,9 @@
<%= stylesheet_link_tag 'blueprint/print', :media => 'print' %>
<!--[if lt IE 8]><%= stylesheet_link_tag 'blueprint/ie' %><![endif]-->
<%= stylesheet_link_tag 'custom', :media => 'screen' %>
+
+
+ <%= javascript_include_tag "application" %>
+ <%= csrf_meta_tags %>
+ </head>
+
View
43 app/views/layouts/application.html.erb
@@ -1,43 +1,13 @@
<!DOCTYPE html>
<html>
- <head>
- <title>Social Network | <%= @title %></title>
-
- <!--[if lt IE 9]>
- <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
- <![endif]-->
- <%= stylesheet_link_tag 'blueprint/screen', :media => 'screen' %>
- <%= stylesheet_link_tag 'blueprint/print', :media => 'print' %>
- <!--[if lt IE 8]><%= stylesheet_link_tag 'blueprint/ie' %><![endif]-->
- <%= stylesheet_link_tag 'custom', :media => 'screen' %>
+ <%= render 'layouts/style_and_meta' %>
- <%= javascript_include_tag "application" %>
- <%= csrf_meta_tags %>
- </head>
<body>
<div class="container">
- <header>
- <%= image_tag("logo.png", :alt => "Ruby School", :class => "round") %>
- <nav class="round">
- <ul>
- <li><%= link_to "Home", root_path %></li>
- <li><%= link_to "Users", :userslist %></li>
- <% if current_user %>
- <li><%= link_to "Edit Profile", edit_user_path(current_user.id) %></li>
- <li><%= link_to "Logout", :logout %></li>
- <li><%= link_to "downloads", :downloads %></li>
- <li><%= link_to "my_downloads", :my_downloads %></li>
-
- <% else %>
- <li><%= link_to "Register", new_user_path %></li>
- <li><%= link_to "Login", :login %></li>
- <% end %>
- </ul>
- </nav>
- </header>
-
+ <%= render 'layouts/header' %>
+
<div>
<p id="notice"><%= notice %></p>
<p id="alert"><%= alert %></p>
@@ -47,12 +17,5 @@
<%= yield %>
</section>
</div>
-
-<div>
-<br>
-<% if current_user %><% else %>
-<%= link_to "Register", new_user_path, :class => "signup_button round" %>
-<% end %>
-</div>
</body>
</html>
View
42 app/views/layouts/application.html.erb~
@@ -1,43 +1,13 @@
<!DOCTYPE html>
<html>
- <head>
- <title>Social Network | <%= @title %></title>
-
- <!--[if lt IE 9]>
- <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
- <![endif]-->
- <%= stylesheet_link_tag 'blueprint/screen', :media => 'screen' %>
- <%= stylesheet_link_tag 'blueprint/print', :media => 'print' %>
- <!--[if lt IE 8]><%= stylesheet_link_tag 'blueprint/ie' %><![endif]-->
- <%= stylesheet_link_tag 'custom', :media => 'screen' %>
+ <%= render 'layouts/style_and_meta' %>
- <%= javascript_include_tag "application" %>
- <%= csrf_meta_tags %>
- </head>
<body>
<div class="container">
- <header>
- <%= image_tag("logo.png", :alt => "Ruby School", :class => "round") %>
- <nav class="round">
- <ul>
- <li><%= link_to "Home", :home %></li>
- <li><%= link_to "Users", :userslist %></li>
- <% if current_user %>
- <li><%= link_to "Edit Profile", edit_user_path(current_user.id) %></li>
- <li><%= link_to "Logout", :logout %></li>
- <li><%= link_to "downloads", :downloads %></li>
- <li><%= link_to "my_downloads", :my_downloads %></li>
-
- <% else %>
- <li><%= link_to "Register", new_user_path %></li>
- <li><%= link_to "Login", :login %></li>
- <% end %>
- </ul>
- </nav>
- </header>
-
+ <%= render 'layouts/header' %>
+
<div>
<p id="notice"><%= notice %></p>
<p id="alert"><%= alert %></p>
@@ -47,11 +17,11 @@
<%= yield %>
</section>
</div>
-
<div>
-<!--<% if current_user %><% else %>
+<br>
+<% if current_user %><% else %>
<%= link_to "Register", new_user_path, :class => "signup_button round" %>
-<% end %>-->
+<% end %>
</div>
</body>
</html>
View
12 app/views/messages/create.html.erb
@@ -0,0 +1,12 @@
+<h1>Writing message to <%= @recipient.username %></h1>
+
+<%= form_for @message do |f| %>
+ <div class="field">
+ <%= f.label :content %><br />
+ <%= f.text_field :content %>
+ </div>
+ <div class="actions">
+ <%= f.submit "Submit" %>
+ </div>
+<% end %>
+<%= link_to 'Back', @recipient %>
View
7 app/views/messages/index.html.erb
@@ -0,0 +1,7 @@
+<% @messages.each do |message|%>
+ <div class="field">
+ <%= message.content %>
+ <%= message.user.username %>
+ </div>
+
+<% end %>
View
11 app/views/messages/show.html.erb
@@ -0,0 +1,11 @@
+<p>
+ <b>From:</b>
+ <%= @message.user.username %>
+</p>
+
+<p>
+ <b>Message:</b>
+ <%= @message.content %>
+</p>
+
+<%= link_to 'Back', :root %>
View
2  app/views/pages/home.html.erb
@@ -14,5 +14,3 @@
</tr>
</table>
- <h1>Social Network</h1>
- <%= link_to 'New User', new_user_path %>
View
17 app/views/pages/home.html.erb.save
@@ -1,17 +0,0 @@
-<% if signed_in? %>
-<table class="front" summary="For signed-in users">
-<tr>
-<td class="main">
-<h1 class="micropost">What's up?</h1>
-<%= render 'shared/micropost_form' %>
-</td>
-<td class="sidebar round">
-<%= render 'shared/user_info' %>
-</td>
-</tr>
-</table>
-<% else %>
-<h1>Sample App<
-
-<%= link_to 'New User', new_user_path %>
-<% end %>
View
4 app/views/posts/_post.html.erb
@@ -8,9 +8,7 @@
<% user = post.user rescue User.find(post.user_id) %>
<% if current_user?(user) %>
<td>
-<%= link_to "delete", post, :method => :delete,
-:confirm => "You sure?",
-:title => post.content %>
+<%= link_to "delete", post, :method => :delete,:confirm => "You sure?",:title => post.content %>
</td>
<% end %>
View
4 app/views/shared/_feed.html.erb.save
@@ -1,4 +0,0 @@
- table class="posts" summary="Status feed">
- <%= render :partial => 'shared/feed_item', :collection => @feed_items %>
- </table>
-
View
2  app/views/uploads/index.html.erb
@@ -13,7 +13,7 @@
<tr>
<td><%= file.name %></td>
<td><%= file.description %></td>
- <td><%= link_to "#{file.user_id}", file.user %></td>
+ <td><%= link_to "#{file.user.username}", file.user %></td>
<td><%= link_to 'Show', file %></td>
<td><%= link_to 'Edit', edit_upload_path(file) %></td>
View
3  app/views/users/index.html.erb
@@ -15,8 +15,7 @@
<td><%= user.email %></td>
<td><%= link_to 'Show', user %></td>
<td><%= link_to 'Edit', edit_user_path(user) %></td>
- <td><%= link_to 'Destroy', user, confirm: 'Are you sure?', method: :delete %></td>
- </tr>
+ </tr>
<% end %>
</table>
View
8 app/views/users/show.html.erb
@@ -1,12 +1,12 @@
<table class="profile">
<tr>
<td class="sidebar round">
- <strong>Name</strong> <%= @user.username %><br />
+ <strong>Name</strong> <%= link_to @user.username, @user %><br />
<strong>E-mail</strong> <%= @user.email %><br />
- <strong>URL</strong> <%= link_to user_path(@user), @user %><br />
<strong>Posts</strong> <%= @user.posts.count %>
- <br>
- <%= link_to 'Edit', edit_user_path(@user) %> | <%= link_to 'Back', users_path %>
+ <%= link_to "Downloads", :downloads %>
+ <br>
+ <%= link_to 'Edit', edit_user_path(@user) %> | <%= link_to 'Back', users_path %> | <%= link_to 'write', send_message_path(@user) %>
</td>
</tr>
</table>
View
6 config/routes.rb
@@ -6,7 +6,8 @@
resources :uploads
resources :userlist
resources :posts, :only => [:create, :destroy]
-
+ resources :messages
+
match 'login' => 'user_sessions#new', :as => :login
match 'userslist' => 'users#index', :as => :userslist
match 'logout' => 'user_sessions#destroy', :as => :logout
@@ -14,7 +15,8 @@
match 'my_downloads' => 'uploads#user_uploads', :as => :my_downloads
match 'add_upload_to_favorite/:id' => 'uploads#add_to_favorite', :as => :add_upload_to_favorite
match 'delete_upload_from_favorite/:id' => 'uploads#delete_from_favorites', :as => :delete_upload_from_favorite
-
+ match 'send_message/:id' => 'messages#create', :as => :send_message
+
# The priority is based upon order of creation:
# first created -> highest priority.
View
10 db/migrate/20120305154705_create_messages.rb
@@ -0,0 +1,10 @@
+class CreateMessages < ActiveRecord::Migration
+ def change
+ create_table :messages do |t|
+ t.integer :user_id
+ t.text :content
+
+ t.timestamps
+ end
+ end
+end
View
10 db/migrate/20120305154753_create_messages_recipients.rb
@@ -0,0 +1,10 @@
+class CreateMessagesRecipients < ActiveRecord::Migration
+ def change
+ create_table :message_recipients do |t|
+ t.integer :user_id
+ t.integer :message_id
+
+ t.timestamps
+ end
+ end
+end
View
16 db/schema.rb
@@ -11,7 +11,21 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120229072349) do
+ActiveRecord::Schema.define(:version => 20120305154753) do
+
+ create_table "message_recipients", :force => true do |t|
+ t.integer "user_id"
+ t.integer "message_id"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+ create_table "messages", :force => true do |t|
+ t.integer "user_id"
+ t.text "content"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
create_table "posts", :force => true do |t|
t.string "content"

No commit comments for this range

Something went wrong with that request. Please try again.