Sha256: b7a1ec0a6a90b197d5dc33029f50c6313de9bca5a18beb12bcb1f5e3414d10cd

Contents?: true

Size: 1.44 KB

Versions: 20

Compression:

Stored size: 1.44 KB

Contents

require_dependency "my_forum/application_controller"

module MyForum
  class PrivateMessagesController < ApplicationController

    before_filter :only_for_registered_users

    def index
      @private_messages = PrivateMessage.inbox_for(current_user).paginate(per_page: 16, page: params[:page])
      render :inbox
    end

    def inbox

    end

    def outbox

    end

    def deleted

    end

    def new
      @pm = PrivateMessage.new
      @reply_pm = PrivateMessage.find(params[:reply_for_id]) if params[:reply_for_id]
    end

    def create
      @pm = PrivateMessage.new
      recipient = begin
        User.find_by_login(params[:private_message].delete(:recipient))
      rescue
        #TODO send notification to admin
        nil
      end

      unless recipient
        @pm.errors.add(:base, t('.cant_find_recipient'))
        render :new
        return
      end

      @pm.recipient_id = recipient.id
      @pm.recipient_login = recipient.login
      @pm.sender_id = current_user_id
      @pm.sender_login = current_user.login
      @pm.assign_attributes(pm_params)
      @pm.save

      redirect_to action: :index
    end

    def show
      @pm = PrivateMessage.inbox_for(current_user).find(params[:id])
      @pm.update!(unread: false)
    end

    private

    def pm_params
      params.require(:private_message).permit(:subject, :body)
    end

    def only_for_registered_users
      redirect_to root_path unless current_user
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
my_forum-0.0.1.beta23 app/controllers/my_forum/private_messages_controller.rb
my_forum-0.0.1.beta22 app/controllers/my_forum/private_messages_controller.rb
my_forum-0.0.1.beta21 app/controllers/my_forum/private_messages_controller.rb
my_forum-0.0.1.beta20 app/controllers/my_forum/private_messages_controller.rb
my_forum-0.0.1.beta19 app/controllers/my_forum/private_messages_controller.rb
my_forum-0.0.1.beta18 app/controllers/my_forum/private_messages_controller.rb
my_forum-0.0.1.beta17 app/controllers/my_forum/private_messages_controller.rb
my_forum-0.0.1.beta16 app/controllers/my_forum/private_messages_controller.rb
my_forum-0.0.1.beta15 app/controllers/my_forum/private_messages_controller.rb
my_forum-0.0.1.beta14 app/controllers/my_forum/private_messages_controller.rb
my_forum-0.0.1.beta13 app/controllers/my_forum/private_messages_controller.rb
my_forum-0.0.1.beta12 app/controllers/my_forum/private_messages_controller.rb
my_forum-0.0.1.beta11 app/controllers/my_forum/private_messages_controller.rb
my_forum-0.0.1.beta10 app/controllers/my_forum/private_messages_controller.rb
my_forum-0.0.1.beta9 app/controllers/my_forum/private_messages_controller.rb
my_forum-0.0.1.beta8 app/controllers/my_forum/private_messages_controller.rb
my_forum-0.0.1.beta7 app/controllers/my_forum/private_messages_controller.rb
my_forum-0.0.1.beta5 app/controllers/my_forum/private_messages_controller.rb
my_forum-0.0.1.beta4 app/controllers/my_forum/private_messages_controller.rb
my_forum-0.0.1.beta3 app/controllers/my_forum/private_messages_controller.rb