Class: PostmanPat::PmMailsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- PostmanPat::PmMailsController
- Defined in:
- app/controllers/postman_pat/pm_mails_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/postman_pat/pm_mails_controller.rb', line 39 def create success = true recipients = params[:recipients] subject = params[:subject] = params[:message] #[TODO] - do proper exception checking begin result = PostmanPat::PmMail.compose(current_user, recipients, subject, ) flash[:success] = "Message has been sent." rescue Exception, "An error has occured with PmMail.compose method" success = false flash[:error] = "There was a problem sending your message." end respond_to do |format| format.html { redirect_to mail_index_path } format.json { render :json => "{\"success\":#{success}}"} end end |
#destroy ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/controllers/postman_pat/pm_mails_controller.rb', line 79 def destroy success = true pm_mail = PostmanPat::PmMail.get_mail(current_user.id, params[:id]) #[TODO] - do proper exception checking begin pm_mail.mark_deleted! flash[:success] = "Your reply has been sent." rescue Exception success = false flash[:error] = "There was an error sending your reply." end respond_to do |format| format.html { redirect_to mail_index_path } format.json { render :json => "{\"success\":#{success}}"} end end |
#index ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'app/controllers/postman_pat/pm_mails_controller.rb', line 5 def index @title = "Private Messages" @pm_mails = PostmanPat::PmMail.get_all_mail(current_user.id) respond_to do |format| format.html format.json { render :json => @pm_mails.to_json } end end |
#new ⇒ Object
34 35 36 37 |
# File 'app/controllers/postman_pat/pm_mails_controller.rb', line 34 def new @title = "New Private Message" @pm_mail = PostmanPat::PmMail.new end |
#show ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/postman_pat/pm_mails_controller.rb', line 15 def show @pm_mail = PostmanPat::PmMail.get_mail(current_user.id, (params[:id]).to_i) if @pm_mail.nil? flash[:error] = "Private message no longer exists." redirect_to '/' and return end # Mark the mail as read @pm_mail.mark_read! @title = "Private Message: #{@pm_mail..subject}" respond_to do |format| format.html format.json { render :json => @pm_mail.to_json } end end |
#update ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/controllers/postman_pat/pm_mails_controller.rb', line 60 def update success = true pm_mail = PostmanPat::PmMail.get_mail(current_user.id, (params[:id]).to_i) #[TODO] - do proper exception checking begin pm_mail.reply(params[:message]) flash[:success] = "Reply has been sent." rescue Exception success = false flash[:error] = "There was a probly sending your reply." end respond_to do |format| format.html { redirect_to mail_index_path } format.json { render :json => "{\"success\":#{success}}"} end end |