RoR - 邮件中的动态主体(部分)(RoR - Dynamic body (part) in mailer)

我的目标是从db检索邮件程序的正文。

我创建了一个模型,用于存储db中的主体,带有简单的文本,html标签和变量(如原始静态邮件程序的主体),并在邮件程序视图中更改了主体。

我尝试使用<%= raw @body_db.html.html_safe %> ,文本正确地从db导入,但是当我收到邮件时,没有变量的替换。

示例:如果在DB模板中我有Cliente: <%= @nome_cliente %> ,在我的邮件中我收到Cliente: <%= @nome_cliente %>但我想要Cliente: <%= @nome_cliente %> Cliente: Jon Doe

PS:所有变量都可以使用'静态'文本

有人能帮我吗?

谢谢


My goal is to retrieve the a mailer's body from db.

I created a model that store the body in db, with simple text, html tag and variable (as in the original static mailer's body) and changed the piece of body in mailer's view.

I tried with <%= raw @body_db.html.html_safe %> , the text is correctly imported from db, but when i receive the mail there isn't variables's substitution.

Example: if in DB template i have Cliente: <%= @nome_cliente %>, in my mail i receive Cliente: <%= @nome_cliente %> but i want Cliente: Jon Doe

P.S. : All variables are ok using 'static' text

Can someone help me?

Thanks


原文:https://stackoverflow.com/questions/39084453
2024-05-05 17:05

满意答案

在pygame中,您需要使用您编写的代码。

#clear to reload
screen.fill(0)

#drawing background
screen.blit(back, background )

#update
pygame.display.flip()

如果您将一个播放器添加到屏幕然后移动他。 您会注意到,除非您重绘背景,否则您将不止一次看到该角色。

Pygame不只是让你在屏幕上添加图像并移动它,你必须重绘背景以摆脱前一帧。

您应该在代码中添加的另一件事是等待。

clock = pygame.time.Clock()
FPS = 30

while 1:
    clock.tick(FPS)

这将设置帧速率。 我会说你通常会想要30到60帧,具体取决于游戏/硬件。

你当前的程序可能会重新绘制几百帧,所以这肯定会增加滞后。

当我在没有背景的我的电脑Ubuntu 12.04上检查这个。 即黑屏。

我的帧速率在1000 - 2000 FPS之间。


In pygame you need to use this code you wrote.

#clear to reload
screen.fill(0)

#drawing background
screen.blit(back, background )

#update
pygame.display.flip()

If you add a player to the screen and then move him. You will notice that unless you redraw the background, you will see the character more than once.

Pygame doesn't just let you add an image to the screen and move it around, you must redraw the background to get rid of a previous frame.

Another thing you should add to your code is a wait.

clock = pygame.time.Clock()
FPS = 30

while 1:
    clock.tick(FPS)

This will set the frame rate. I'd say you would generally want this at 30 - 60 frames, depending on the game / hardware.

Your current program is probably redrawing the frame a several hundred times, so this will definately add lag.

When I checked this on my pc Ubuntu 12.04 without a background. i.e. A Black screen.

My frame rate was between 1000 - 2000 FPS.

相关问答

更多

在pygame背景中加载多个图像(Loading multiple images in pygame background)

尝试这种方法,或多或少是人们所建议的,以及一些识别问题,如果不是由SO代码样本格式引起的: import pygame from pygame.locals import * from sys import exit #you should rename the Map# from 1 to 9 instead of 01 to 09. ground = ['Map'+ str(image+1) +'.jpg' for image in range(19)] mouse_image = 'p...

PyGame - 获取加载图像的大小(PyGame - Getting the size of a loaded image)

在任何表面上使用convert()函数之前,屏幕需要被初始化。 您可以在set_mode之前加载图像,获取它们的大小,然后在初始化显示后 convert它们,如下所示: import pygame pygame.init() image = pygame.image.load("file_to_load.jph") print image.get_rect().size # you can get size screen = pygame.display.set_mode(image.get...

试图添加一个图像作为pygame背景(trying to add an image as a pygame backgrounds)

首先我不确定你为什么要将背景设为精灵或者类,这似乎是一个不必要的实现。 可以使用pygame.image.load()加载背景,并将其存储为曲面并使其易于显示。 一个简短的例子: import pygame as py py.init() WINDOW_WIDTH = 640 WINDOW_HEIGHT = 360 screen = py.display.set_mode((WINDOW_WIDTH,WINDOW_HEIGHT)) background = py.image.load("im...

移动背景pygame(Moving background pygame)

class Space(pygame.sprite.Sprite): def __init__(self, num): pygame.sprite.Sprite.__init__(self) self.rect.top = num * 600 self.image, self.rect = load_image("space.png", 10) self.dx = -5 self.reset() de...

如何以pygame作为背景加载巨大的图像?(How can I load a huge image with pygame as a background?)

在pygame中,您需要使用您编写的代码。 #clear to reload screen.fill(0) #drawing background screen.blit(back, background ) #update pygame.display.flip() 如果您将一个播放器添加到屏幕然后移动他。 您会注意到,除非您重绘背景,否则您将不止一次看到该角色。 Pygame不只是让你在屏幕上添加图像并移动它,你必须重绘背景以摆脱前一帧。 您应该在代码中添加的另一件事是等待。 clock...

Pygame:添加背景(Pygame: Adding a background)

背景图像与任何其他图像没有区别。 先吧.blit吧。 A background image is no different from any other image. Just .blit it first.

在pygame上使用类显示图像(Displaying an image using a class on pygame)

Sprite没有draw()函数,但是其他函数(即.pygame.sprite.Group )直接使用self.image和self.rect来绘制这个sprite。 你可以创建自己的函数draw()来做同样的事情 def draw(self, screen): screen.blit(self.image, self.rect) 您不必两次加载Enemy.gif 。 在Enemy类或外部进行,然后使用image作为参数Enemy( ..., image) (或使用文件名...

PyGame将cStringIO加载为图像(PyGame load cStringIO as image)

将其添加到DummyFile def tell(self): return self.pos 它认为你的文件类对象不可寻找,因为它缺少该方法。 通过向DummyFile添加__ getattr __方法并查看调用哪种方法来计算出来。 Add this to DummyFile def tell(self): return self.pos It thinks your file-like object is not seekable because it is missing ...

相关文章

更多

ROR study

用migration改资料库schema、index; 不要直接修改资料库,用migration当做作 ...

了解 Web Part 框架

了解 Web Part 框架 发布日期: 4/1/2004 | 更新日期: 4/1/2004 ...

getting start with storm 翻译 第二章 part-1

转载请注明出处:http://blog.csdn.net/lonelytrooper/article/ ...

getting start with storm 翻译 第八章 part-2

转载请注明出处:http://blog.csdn.net/lonelytrooper/article/ ...

《宁皓网:Drupal 6 基础教程 第一部》(Drupal 6 Essential Training Part 1)修正完整版[压缩包]

中文名: 宁皓网:Drupal 6 基础教程 第一部 英文名: Drupal 6 Essenti ...

Java 发送邮件

Java 发送邮件 使用Java应用程序发送E-mail十分简单,但是首先你应该在你的机器上安 ...

Search smarter with Apache Solr, Part 1: Essential features and the Solr schema

Search smarter with Apache Solr, Part 1: Essential ...

Rails中的路由功能是如何对应的?

我才开始接触ROR,我是参照agile web development with rails这本书学习 ...

全球6大垃圾邮件僵尸网络

三周以前 Mega-D的僵尸网络还是世界最大的垃圾邮件源,后来,Mega-D背后的恶意程序 Ozdok ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本