2017-01-10 7 views
0

rails g mailboxer:viewsによって作成されたメールテンプレートにユーザー名を印刷しようとしています。メールボックスのメーラー通知でcurrent_userにアクセス

メソッドとして呼び出すときは、「メソッドまたは変数current_userが見つかりません」と表示されますが、publicメソッドはUserとして呼び出されます。 idは印刷します。

は、ここでビュー

<!DOCTYPE html> 
<html> 
    <head> 
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" /> 
    </head> 
    <body> 
    <h1>You have a new reply from <%= current_user.name %>: <%= @subject %></h1> 
    <blockquote> 
     <p> 
     <%= raw @message.body %> 
     </p> 
    </blockquote> 
    <p> 
     Visit your inbox for more info. 
    </p> 
    </body> 
</html> 

とモデル

class ConversationMessage 
    include ActiveModel::Model 
    include Sanitizable 

    # Attributes 
    attr_accessor :sender, :body, :conversation 


    # Validations 
    validates_presence_of :body 

    # Sanitize contenteditable attributes 
    sanitize_html :body 

    def save 
    if valid? 
     ApplicationRecord.transaction do 
     # In a transaction, as mailboxer performs many inserts 
     sender.reply_to_conversation(conversation, body) 
     end 
    end 
    end 

    def mailbox_full_name 
    full_name 
    end 
end 

そしてmailboxer.rbだ

Mailboxer.setup do |config| 

    #Configures if you application uses or not email sending for Notifications and Messages 
    config.uses_emails = true 

    #Configures the default from for emails sent for Messages and Notifications 
    config.default_from = Settings.env.mailer.sender 

    #Configures the methods needed by mailboxer 
    config.email_method = :mailbox_email 
    config.name_method = :mailbox_full_name 

    #Configures if you use or not a search engine and which one you are using 
    #Supported engines: [:solr,:sphinx] 
    config.search_enabled = false 
    config.search_engine = :solr 

    #Configures maximum length of the message subject and body 
    config.subject_max_length = 255 
    config.body_max_length = 32000 
end 

方法はmailbox_emailカスタムおよびMAILBOX_NAMEのために使用される懸念もあります

module DeliveryMessage::Mailboxable 
    extend ActiveSupport::Concern 

    included do 
    acts_as_messageable 

    def mailbox_full_name 
     full_name 
    end 

    #Returning the email address of the model if an email should be sent for this object (Message or Notification). 
    #If no mail has to be sent, return nil. 
    def mailbox_email(object) 
     email 
    end 
    end 
end 

更新:これはこの問題と同じです。 Show username on Mailboxer inbox in Rails

そして同じように解決されます。

答えて

0

メーラービューからコントローラーヘルパーにアクセスする権限がありません。

代わりに@messageオブジェクトの属性を使用する必要があります。

<h1>You have a new reply from <%= @message.sender.name %>: <%= @subject %></h1> 
+0

こんにちは、@MikDiet それはこのようにアップeneded:あなたは<%= @subject%> ' に<%= @ message.sender.full_name%>からの新しい返信を持って '

はモデル内の 'full_name'メソッドです。 フィードバックいただきありがとうございます。 – zamuro

関連する問題