adding messaging function, needs tests...
This commit is contained in:
@@ -1,14 +1,22 @@
|
||||
class MessagesController < ApplicationController
|
||||
|
||||
def index
|
||||
@messages = Message.where(:receiver_id => current_user.id)
|
||||
@messages = current_user.messages
|
||||
end
|
||||
|
||||
def show
|
||||
@message = Message.where(:id => params[:id])
|
||||
@message = Message.where(:id => params[:id]).first
|
||||
end
|
||||
|
||||
def delete
|
||||
def destroy
|
||||
message = Message.where(:id => params[:id]).first
|
||||
|
||||
if message.destroy
|
||||
flash[:success] = "Your message has been deleted."
|
||||
redirect_to user_messages_path(:user_id => current_user.user_id)
|
||||
else
|
||||
flash[:error] = "Could not delete message."
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@@ -16,6 +24,17 @@ class MessagesController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
if Message.create(params[:message])
|
||||
respond_to do |format|
|
||||
format.html { redirect_to user_messages_path(:user_id => current_user.user_id) }
|
||||
format.json { render :json => {:msg => "success"} }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html { redirect_to user_messages_path }
|
||||
format.json { render :json => {:msg => "failure"} }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user