Ruby on rails 根据页面动态更改横幅

Ruby on rails 根据页面动态更改横幅,ruby-on-rails,image,Ruby On Rails,Image,我对rails非常陌生,我希望有一个根据用户所在页面动态更改的横幅。通常情况下,我会在每个页面的视图中显示横幅图像,但是客户端希望横幅位于导航栏上方,现在我的application.html.erb文件中有导航栏。我该怎么做呢 用户可以使用助手方法 在application.html.erb中的适当位置,放置如下内容: <%= banner_helper %> def banner_helper image_to_use = switch "#{controller_name}

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

用户可以使用助手方法

在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