Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed messages

  • Loading branch information...
commit d21613f0b98a7ba943eeb3ae65d62510df3ff023 1 parent 18c4f44
@strix3000 strix3000 authored
View
11 app/controllers/messages_controller.rb
@@ -2,24 +2,19 @@ class MessagesController < ApplicationController
def create
@recipient = User.find(params[:id])
- @message = Message.new(:content => params[:content], :user => current_user,)
+ @message = Message.new(:content => params[:content], :user => current_user, :recipient => @recipient)
@message.save
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
-
+ @recieved_messages = current_user.recieved_messages
+ @sent_messages = current_user.messages
end
def update
View
6 app/views/messages/_message.html.erb
@@ -0,0 +1,6 @@
+<div class="message">
+ <%= link_to message.content, message %> (c)
+ <%= link_to message.user.username, message.user %>
+ <%= link_to 'Answer', send_message_url(:id => message.user.id) %>
+</div>
+
View
19 app/views/messages/index.html.erb
@@ -1,7 +1,12 @@
-<% @messages.each do |message|%>
- <div class="field">
- <%= message.content %> (c)<%= link_to message.user.username, message.user %>
- <%= link_to "Answer", :send_message%>
- </div>
-_____________________________________________________________________
-<% end %>
+<p>Recieved<p>
+<% if @recieved_messages %>
+ <%= render :partial => 'message', :collection => @recieved_messages %>
+<% else %>
+ You have no messages.
+<%end%>
+<p>Sent<p>
+<% if @sent_messages %>
+ <%= render :partial => 'message', :collection => @sent_messages %>
+<% else %>
+ You have no messages.
+<%end%>
View
15 app/views/messages/show.html.erb
@@ -1,14 +1,3 @@
-<p>
- <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 %>
-</p>
-
+<render 'message'>
<%= link_to 'Back', :root %>
+
View
9 app/views/messages/user_messages.html.erb
@@ -1,9 +0,0 @@
-<% 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%>
Please sign in to comment.
Something went wrong with that request. Please try again.