根据页面动态更改横幅

时间:2013-11-11 21:32:23

标签: ruby-on-rails image

我对rails非常陌生,我希望有一个可以根据用户所在页面动态更改的横幅。通常我会在每个页面的视图中都有横幅图像,但客户希望横幅位于导航栏上方,现在我的application.html.erb文件中有导航栏。我该怎么做呢?

Example of how the page is laid out

1 个答案:

答案 0 :(得分:2)

使用辅助方法。

在application.html.erb中,在适当的位置输入类似的内容:

<%= banner_helper %>

然后在帮助器中定义:

def banner_helper
  image_to_use = switch "#{controller_name}_#{action_name}" do
    when 'home_index'; 'homepage_banner.gif'
    else 'some_other_image.gif'
  end
  content_tag :img, src: image_to_use, alt: 'some text'
end