Ruby on Rails 应用程序,我有一个带有超链接的“引导”行图像。我只想显示其中包含内容的内容。
这是一个例子:
<div class="span3">
<h5 class="pagination-centered">
<%= link_to (image_tag "/img/folder.jpg", alt: "Buyer's Guides", width: "75px"), action: "index", filter: @filter, type: "buyers_guides" %>
<%= link_to "Buyer's Guides", action: "index", filter: @filter, type: "buyers_guides" %>
</h5>
</div>
<div class="span3">
<h5 class="pagination-centered">
<%= link_to (image_tag "/img/folder.jpg", alt: "Datasheets", width: "75px"), action: "index", filter: @filter, type: "datasheets" %>
<%= link_to "Datasheets", action: "index", filter: @filter, type: "datasheets" %>
</h5>
</div>
使用 if else 语句可以吗?否则,否则?
或者控制器呢?
class Users::MarketingController < ApplicationController
def index
@filter = params[:filter]
@type = params[:type]
if @filter
if @type
arrays_of_strings_to_check_against = ['logos', 'datasheets', 'buyers_guides', 'videos', 'web_banners', 'presentations', 'documents', 'press_releases' ]
if arrays_of_strings_to_check_against.any?{ |o| @type =~ /\b#{Regexp.escape(o)}\b/ }
base_dir = "public/files/marketing"
@files = Dir.glob("#{base_dir}/voip/#{@filter}/#{@type.downcase}/*.[a-z]*")
@view = "files"
else
@view = 'types'
end
else
@view = 'types'
end
else
@view = "category"
end
end
结尾
对此并不陌生,并试图学习良好的做法。谢谢