Permalink
Browse files

Merge branch 'messages'

Conflicts:
	app/views/uploads/_form.html.erb
	config/routes.rb
  • Loading branch information...
2 parents 463e19a + 49c84f1 commit 6efa41b2aed005f62e71f9a04841d726419a0f4f @strix3000 strix3000 committed Mar 16, 2012
@@ -2,24 +2,26 @@ class MessagesController < ApplicationController
def create
@recipient = User.find(params[:id])
- @message = Message.new()
- @message.content = params[:content]
- @message.user = current_user
+ @message = Message.new(:content => params[:content], :user => current_user)
@message.save
- mes_recipient = MessageRecipient.new()
- mes_recipient.message_id = @message.id
- mes_recipient.user_id = 1
+ mes_recipient = MessageRecipient.new(:message => @message, :user => @recipient)
mes_recipient.save
end
def show
@message = Message.find(params[:id])
+ @recipients = @message.recipients
end
def index
@messages = current_user.messages + current_user.recieved_messages
end
+def user_messages
+ @messages = current_user.recieved_messages
+
+end
+
def update
@message = Message.find(params[:id])
@@ -31,7 +33,7 @@ def update
format.html { render action: "edit" }
format.json { render json: @message.errors, status: :unprocessable_entity }
end
- end
- end
-
+
+end
+end
end
@@ -15,19 +15,10 @@ def index
#Shows only one chosen file? with description.
def show
@file = Upload.find(params[:id])
- respond_to do |format|
- format.html # show.html.erb
- format.json { render json: @file }
- end
end
def new
@file = Upload.new
-
- respond_to do |format|
- format.html # new.html.erb
- format.json { render json: @file }
- end
end
# GET /files/1/edit
@@ -38,7 +29,7 @@ def edit
# POST /files
# POST /files.json
def create
- @file = Upload.new(params[:upload])
+ @file = Upload.new(params[:upload])
@file.user = current_user
respond_to do |format|
if @file.save
@@ -72,21 +63,14 @@ def update
def destroy
@file = Upload.find(params[:id])
@file.destroy
-
- respond_to do |format|
- format.html { redirect_to uploads_url }
- format.json { head :ok }
- end
end
def user_uploads
@files = current_user.saved_uploads + current_user.uploads
end
def add_to_favorite
- favourite_upload = UsersUpload.new
- favourite_upload.user = current_user
- favourite_upload.upload = Upload.find(params[:id])
+ favourite_upload = UsersUpload.new(:user => current_user,:upload => Upload.find(params[:id]))
if favourite_upload.save
respond_to do |format|
format.html { redirect_to uploads_url }
View
@@ -1,7 +1,7 @@
class Message < ActiveRecord::Base
#Relations
belongs_to :user
- has_many :message_recipients
+ has_many :message_recipients
has_many :recipients, :through => :message_recipients, :source => :user
#Validations
validate :user_id, :presence => true
@@ -6,9 +6,9 @@
<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 "Logout(#{current_user.username},#{current_user.id})", :logout %></li>
<li><%= link_to "my_downloads", :my_downloads %></li>
-
+ <li><%= link_to "inbox", :my_messages%>
<% else %>
<li><%= link_to "Register", new_user_path %></li>
<li><%= link_to "Login", :login %></li>
@@ -1,7 +1,7 @@
<% @messages.each do |message|%>
<div class="field">
- <%= message.content %>
- <%= message.user.username %>
+ <%= message.content %> (c)<%= link_to message.user.username, message.user %>
+ <%= link_to "Answer", :send_message%>
</div>
-
+_____________________________________________________________________
<% end %>
@@ -2,7 +2,10 @@
<b>From:</b>
<%= @message.user.username %>
</p>
-
+<p>
+ <b>To:</b>
+ <% @recipients.each do |recipient|%> <%= recipient.username %> <%end%>
+</p>
<p>
<b>Message:</b>
<%= @message.content %>
@@ -0,0 +1,9 @@
+<% if @messages %>
+<% @messages.each do |message|%>
+ <div class="field">
+ <%= message.content %> (c)<%= link_to message.user.username, message.user %>
+ </div>
+ <%end%>
+<% else %>
+ You have no messages.
+<%end%>
@@ -23,7 +23,8 @@
<%= f.label :description %><br />
<%= f.text_field :description %>
</div>
- <div class="actions">
+
+ <div class="actions">
<%= f.submit %>
</div>
<% end %>
@@ -15,8 +15,7 @@
<td><%= file.description %></td>
<td><%= link_to 'Show', file %></td>
<td><%= link_to 'Edit', edit_upload_path(file) %></td>
- <!-- <td><%= link_to 'Destroy', file, confirm: 'Are you sure?', method: :delete %></td> -->
- <% if file.user == current_user %>
+ <% if file.user?(current_user) %>
<td><%= link_to 'Destroy file', file, method: :delete %></td>
<% else %>
<td><%= link_to 'Remove from favorite', delete_upload_from_favorite_path(file) %></td>
@@ -6,7 +6,7 @@
<strong>Posts</strong> <%= @user.posts.count %>
<%= link_to "Downloads", :downloads %>
<br>
- <%= link_to 'Edit', edit_user_path(@user) %> | <%= link_to 'Back', users_path %> | <%= link_to 'write', send_message_path(@user) %>
+ <%= link_to 'Edit', edit_user_path(@user) %> | <%= link_to 'Back', users_path %> | <%= link_to 'write', :send_message%>
</td>
</tr>
</table>
View
@@ -7,7 +7,7 @@
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
@@ -16,7 +16,7 @@
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
-
+ match 'my_messages' => "messages#user_messages", :as => :my_messages
# The priority is based upon order of creation:
# first created -> highest priority.

0 comments on commit 6efa41b

Please sign in to comment.