Permalink
Browse files

Merge branch 'messages'

Conflicts:
	app/views/layouts/application.html.erb
  • Loading branch information...
2 parents 54c4cab + ce0b365 commit 463e19a045df0cb3ef9ee3399fbe1042336758f3 @strix3000 strix3000 committed Mar 12, 2012
View
@@ -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
@@ -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)
@@ -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/
@@ -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/
@@ -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
@@ -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.') }
@@ -0,0 +1,2 @@
+module MessageHelper
+end
View
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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>
@@ -1,7 +1,16 @@
+ <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' %>
+
+
+ <%= javascript_include_tag "application" %>
+ <%= csrf_meta_tags %>
+ </head>
+
@@ -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>
@@ -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>
@@ -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 %>
@@ -0,0 +1,7 @@
+<% @messages.each do |message|%>
+ <div class="field">
+ <%= message.content %>
+ <%= message.user.username %>
+ </div>
+
+<% end %>
@@ -0,0 +1,11 @@
+<p>
+ <b>From:</b>
+ <%= @message.user.username %>
+</p>
+
+<p>
+ <b>Message:</b>
+ <%= @message.content %>
+</p>
+
+<%= link_to 'Back', :root %>
@@ -14,5 +14,3 @@
</tr>
</table>
- <h1>Social Network</h1>
- <%= link_to 'New User', new_user_path %>
@@ -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 %>
@@ -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 %>
@@ -1,4 +0,0 @@
- table class="posts" summary="Status feed">
- <%= render :partial => 'shared/feed_item', :collection => @feed_items %>
- </table>
-
@@ -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>
@@ -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>
Oops, something went wrong.

0 comments on commit 463e19a

Please sign in to comment.