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