Advertisement
theminijohn

Untitled

Aug 16th, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.52 KB | None | 0 0
  1. class MessagesController < ApplicationController
  2.     before_filter :authenticate_user!, only: [:index, :create]
  3.  
  4.     def index
  5.         @messages = Messages.where(receiver_id: current_user.id)
  6.     end
  7.  
  8.     def create
  9.         message = Message.new(params[:message])
  10.         message.recipient_id = current_user.id
  11.         if message.save
  12.             flash[:success] = "Message was sent successfully"
  13.             redirect_to :index
  14.         else
  15.             flash[:error] = message.errors.full_messages.join(", ")
  16.             redirect_to :new
  17.         end
  18.  
  19.         message.save!
  20.     end
  21.  
  22.     def new
  23.         @message = Message.new
  24.     end
  25.  
  26. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement