I have just updated to Mailboxer 0.12.4 and followed the instructions in the Github Readme. I had two controllers for working with the Gem
Notifications
class NotificationsController < ApplicationController
before_action :signed_in_user, only: [:create]
def new
@user = User.find(:user)
@message = current_user.messages.new
end
def create
@recepient = User.find(params[:notification][:id])
current_user.send_message(@recepient, params[:notification][:body],params[:notification][:subject])
flash[:success] = "Message has been sent!"
redirect_to user_path @recepient
end
end
Conversations
class ConversationsController < ApplicationController
before_action :signed_in_user
def index
@conversations = current_user.mailbox.conversations.paginate(page: params[:page],:per_page => 5)
end
def show
@conversation = current_user.mailbox.conversations.find_by( :id => params[:id] )
@receipts = @conversation.receipts_for(current_user).reverse!
end
end
My users model has act_as_messagable. After the update this method in my users controller is throwing an error.
uninitialized constant UsersController::Notification
the code that is highlighted is
def show
@user = User.find(params[:id])
@message = Notification.new << this line
....
end
I have tried creating a Notification object in the console and I get the same error. I have read that the update has changed the namespacing but I don't know how to change my code to account for this.
This is the closest I have found to a solution but the guy doesn't say how he fixed it
Ok I got this working I need to figure out why but it seems to be related to namespaces that were introduced in the upgrade to 0.12.4.
Step 1: Change my controllers to
mailboxer_notification_controller.rb
Note: that the param names needed to change
mailboxer_conversations_controller.rb
Step 2: Anywhere I accessed a method belonging to theses controllers needed to be updated with the correct namespace
Step 3: Update your config/routes.rb
I'm not sure of the exact reasons these fixes work, I need to spend more time reading about namespaces in rails. If anyone has a good explanation feel free to add to the answer