2014-11-16 108 views
0

我剛剛更新到Mailboxer 0.12.4並遵循Github自述文件中的說明。我有兩個控制器,用於創業板從Mailboxer 0.11.0升級到0.12.4的問題

通知工作

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 

對話

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 

我的用戶模型act_as_messagable。更新後,我的用戶控制器中的這個方法拋出一個錯誤。

未初始化的常量UsersController ::通知

的代碼高亮顯示是

def show 
    @user = User.find(params[:id]) 
    @message = Notification.new << this line 
    .... 
end 

我試圖創建在控制檯中通知的對象,我也得到了同樣的錯誤。我讀過更新已經改變了命名空間,但我不知道如何改變我的代碼來解決這個問題。

This is the closest I have found to a solution but the guy doesn't say how he fixed it

回答

1

好吧我得到這個工作,我需要弄清楚爲什麼,但它似乎是與在升級被引入0.12.4該命名空間。

第1步:更改我的控制器

mailboxer_notification_controller.rb

class MailboxerNotificationsController < 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[:mailboxer_notification][:id]) 

     current_user.send_message(@recepient, params[:mailboxer_notification][:body],params[:mailboxer_notification][:subject]) 
     flash[:success] = "Message has been sent!" 

     redirect_to user_path @recepient 
    end 
end 

注:是需要改變帕拉姆名稱

mailboxer_conversations_controller.rb

class MailboxerConversationsController < 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 

第2步:無論我訪問的方法屬於需要用正確的命名空間進行更新論文控制器

def show 
    @user = User.find(params[:id]) 
    @message = Mailboxer::Notification.new 

    .... 
end 

第3步:更新您的config/routes.rb文件

SampleApp::Application.routes.draw do 
    resources :mailboxer_conversations 
    resources :mailboxer_notifications, only: [:create] 

    match '/sendMessage', to: 'mailboxer_notifications#create', via: 'post' 

    match '/conversations', to: 'mailboxer_conversations#index', via: 'get' 
    match '/conversation', to: 'mailboxer_conversations#show',  via: 'get' 
    .... 
end 

我不確定這些修復工作的確切原因,我需要花更多時間閱讀關於rails中的命名空間。如果有人有一個很好的解釋隨時添加到答案