Rails 6 图像未显示在 Heroku 暂存中



我在欢迎控制器中定义了一些背景图像,因此根据视图图像的变化,在本地工作,但是当我在 Heroku 中部署时,它停止显示背景图像。

该应用程序位于 Rails 6 中,图像和从资产文件夹中获取。 背景图像正在课程视图中加载

标题部分,我正在加载图像:

<section style="background-image:url(<%= @background_image%>)" class="banner <%= 'short-banner' unless @index%>" role="banner">

欢迎控制器:

def index
@background_image = '/assets/computer_low_res.jpg'
@title = 'BOGOTA BOOTCAMP'
end
def learn
@background_image = '/assets/two_computers_low_res.jpg'
@title = 'Try some Ruby'
end
def courses
@background_image = 'https://s3.us-east-2.amazonaws.com/bogota-bootcamp/about-program.jpg'
@title = 'Courses'
end

检查env/production.rb

此行并使其true并再次部署。让我知道...

#config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
config.public_file_server.enabled = true

解决了! 更改标题:

<section style="background-image:url(<%= asset_path(@background_image)%>)" class="banner <%= 'short-banner' unless @index%>" role="banner">

控制器:

def index
@background_image = 'computer_low_res.jpg'
@title = 'BOGOTA BOOTCAMP'
end
def learn
@background_image = 'two_computers_low_res.jpg'
@title = 'Try some Ruby'
end
def courses
@background_image = 'https://s3.us-east-2.amazonaws.com/bogota-bootcamp/about-program.jpg'
@title = 'Courses'
end

相关内容

  • 没有找到相关文章

最新更新