2013-10-18 29 views
1

我想在設計確認消息中添加用戶的電子郵件地址,現在確認郵件發送後,設計顯示我「帶有確認鏈接的消息已發送到您的電子郵件地址。請打開鏈接激活您的帳戶。「但我想要插入註冊用戶的電子郵件,所以它應該是類似於「帶有確認鏈接的消息已發送到您的#{params [:user] [:email]}。請打開鏈接以激活你的帳戶。」devise.en.yml文件中的變量

但不顯示電子郵件,它只是顯示文本。任何建議如何做到這一點?

回答

3

今天解決了這個問題,所以認爲應該爲其他人發佈答案。不得不重寫色器件註冊控制器創建與此代碼行動:

class RegistrationsController < Devise::RegistrationsController 
    # POST /resource 
    def create 
    build_resource(sign_up_params) 
    if resource.save 
     # this block will be used when user is saved in database 
     if resource.active_for_authentication? 
     # this block will be used when user is active or not required to be confirmed 
     set_flash_message :notice, :signed_up if is_navigational_format? 
     sign_up(resource_name, resource) 
     respond_with resource, :location => after_sign_up_path_for(resource) 
     else 
     # this block will be used when user is required to be confirmed 
     user_flash_msg if is_navigational_format? #created a custom method to set flash message 
     expire_session_data_after_sign_in! 
     respond_with resource, :location => after_inactive_sign_up_path_for(resource) 
     end 
    else 
     # this block is used when validation fails 
     clean_up_passwords resource 
     respond_with resource 
    end 
    end 

    private 

    # set custom flash message for unconfirmed user 
    def user_flash_msg 
    if resource.inactive_message == :unconfirmed 
     #check for inactive_message and pass email variable to devise locals message 
     set_flash_message :notice, :"signed_up_but_unconfirmed", email: resource.email 
    else 
     set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" 
    end 
    end 
end 

然後使devise.en.yml文件neccessary變化,我們都設置

en: 
    devise: 
    registrations: 
     signed_up_but_unconfirmed: "A confirmation link has been sent to %{email}. Click the link to activate your account." 

PS檢查發生了什麼

評論
0

Rails的指南國際化涵蓋這種情況下:http://guides.rubyonrails.org/i18n.html#passing-variables-to-translations

在視圖:

# app/views/home/index.html.erb 
<%=t 'greet_username', user: "Bill", message: "Goodbye" %> 

在區域文件:

# config/locales/en.yml 
en: 
    greet_username: "%{message}, %{user}!" 

UPDATE:

# app/views/home/index.html.erb 
<%=t 'email_message', email: params[:user][:email] %> 

# config/locales/en.yml 
en: 
    email_message: "Your email address is : %{email}" 
+0

您可以更具體地瞭解如何將用戶的電子郵件放在devise.en.yml中。當用戶點擊註冊時,我可以通過params [:user] [:email]得到他/她的電子郵件,我試過了%{params [:user] [:email]}裏面的錯誤信息,但它只是給我的文本,而不是用戶的電子郵件 – Mandeep

+0

請參閱上面的更新。 –

+0

我需要從控制器中設置它而不是查看 – Mandeep