0
在我的應用程序的控制器中創建一條記錄後,我想自動打開客戶端的whatsapp,sms或電子郵件應用程序(取決於新記錄的類型)。Rails:控制器中的觸發事件
我創建操作是這樣的:
def create
session[:return_to] ||= request.referer
@token = SecureRandom.uuid
@new_token = Token.new(:token_value => @token, :sender_id => current_user.id, :card_id => params[:card_id], :type => params[:type])
respond_to do |format|
format.html { redirect_to session.delete(:return_to), notice: "Token " + @new_token.token_value + " was successfully created." }
end
if @new_token.type == "sms"
#open client's sms app and autofill sms body with @new_token.token_value
elsif @new_token.type == "email"
#open client's email app and autofill subject + body with @new_token.token_value
elsif @new_token.type == "whatsapp"
#open client's whatsapp and autofill body with @new_token.token_value
end
end
我怎樣才能做到這一點?
它的工作原理!但是,只有當我指定一個電子郵件地址時纔會這樣做。如果我將它留空 - 比如'mailto:?body ...「,它不起作用。是否有解決方案(因爲在我的情況下,地址應該是空的) – Oliver
您應該可以這樣做:https: //stackoverflow.com/questions/3540664/how-do-you-create-a-mailto-link-without-the-to-part ...但也許你可以解決它與%20(一個空格?) – murb
我嘗試了兩種方法,但是隻有在mailtto之後有一個「@」時,redirect_to纔有效: – Oliver