我需要根据评论的数量显示不同的文本,并且我已经将逻辑放在了控制器中。但是在控制器中有一个长方法似乎不是很干,我应该把它放在哪里呢?
example_controller.rb:
def index
.
count_dependent_message
.
end
def count_dependent_message
case @user.comment.count
when 0
@strong = "example Strong 0"
@paragraph = "example paragraph 0"
when 1
@strong = "Jon Smith is called Smith"
@paragraph = "example paragraph 1"
when 2...10
@strong = "Once upon a time...Steve Jobs... "
@paragraph = "example paragraph 2"
when 11...40
@strong = "Wow you have many counts"
@paragraph = "example paragraph 3"
else
@strong = "exciting"
@paragraph = "example paragraph 4"
end
end
看法:
<h3>
<strong>
<%= @strong %>
</strong>
</h3>
<p>
<%= @paragraph %>
</p>
我考虑过将逻辑放在部分中,但这似乎不是很有效,因为我要渲染的文本只是一个句子。