我正在尝试按照Presenter设计模式构建我的Rails应用。我的页面的一部分包含嵌套在锚标记内的几个div,使用常规html工作正常,但是当我尝试使用ActionView帮助程序渲染它时不起作用。
我的观点如下:
class Presenter < SimpleDelegator
def initialize(model, view)
@model, @view = model, view
super @model
end
def h
@view
end
def header
if @model.header.present?
h.content_tag :div, @model.header
end
end
def subheader
if @model.subheader.present?
h.content_tag :div, @model.subheader
end
end
def cta_button
if @model.text.present?
h.content_tag :div, @model.text
end
end
def cta_background
h.link_to @model.target do
yield
nil
end
end
end
我的演讲者课程:
<div class="hero-container clear">
<div>Eaque ea adipisci accusantium.</div>
<div>Sed quibusdam amet et voluptatum.</div>
<div>Click here</div>
<a href="/products">products</a>
</div>
它最终会呈现如下的html:
def gradeChecker(grade):
try:
grade = float(grade)
while (grade < 0) or (grade > 100):
print("Sorry, your grade must be between 0 and 100.")
grade = input("What grade did you receive on: %s? " % assignment)
gradeChecker(grade)
except:
print("Sorry, that's an invalid input. Please only use numbers and decimal points!")
grade = input("What grade did you receive on: %s? " % assignment)
else:
Assignments[assignment].append(grade)
我的目标是在锚标记中设置三个div ,这是通过将它们传递到link_to
函数中来完成的。当我从其他方法调用该块时,为什么它不起作用?