Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 使标志可互换。我应该通过scss.erb还是在应用程序布局中执行此操作?_Ruby On Rails_Ruby_Sass_Carrierwave - Fatal编程技术网

Ruby on rails 使标志可互换。我应该通过scss.erb还是在应用程序布局中执行此操作?

Ruby on rails 使标志可互换。我应该通过scss.erb还是在应用程序布局中执行此操作?,ruby-on-rails,ruby,sass,carrierwave,Ruby On Rails,Ruby,Sass,Carrierwave,我正在尝试使我的rails应用程序的徽标可互换,请参阅上一篇文章 我有一个Logo模型,它有以下字段名称:string,image:string,default:boolean 我正在使用carrierwave gem将图像上载到image:string列。 app/models/logo.rb class Logo < ActiveRecord::Base mount_uploader :image, LogoUploader scope :default, where(default:

我正在尝试使我的rails应用程序的徽标可互换,请参阅上一篇文章

我有一个Logo模型,它有以下字段名称:string,image:string,default:boolean

我正在使用carrierwave gem将图像上载到image:string列。
app/models/logo.rb

class Logo < ActiveRecord::Base
mount_uploader :image, LogoUploader
scope :default, where(default: true)

def falsify_all_others
  Logo.where('id != ?', self.id).each do |item|
    item.default = false
    item.save
    end
  end
end
因此,一旦他们通过carrierwave创建/上传了一些图像,我就会像这样显示徽标: app/views/logos/show.html.erb

<%= image_tag @logo.image_url.to_s %>

我想添加默认的徽标(通过我的徽标范围找到)以显示在主页上。现在,它是通过app/assets/stylesheets/styles.scss.erb通过以下代码完成的

section#header {
height: 220px;
position: relative;
h1 {
    background-image: url('<%= asset_path 'logo.png' %>');
    position: absolute;
    width: 412px;
    height: 188px;
    z-index: 999;
}
节#标题{
高度:220px;
位置:相对位置;
h1{
背景图像:url(“”);
位置:绝对位置;
宽度:412px;
高度:188px;
z指数:999;
}

所以我的问题是:我是否需要将显示徽标的代码从scss.erb中拉出并添加到app/views/layouts/application.html.erb中,或者我可以在scss中更改它?比如用图像标签替换资产路径,或者类似的东西?如果您需要更多信息/代码,我很乐意提供……提前谢谢uld建议不要将其放在SCS中,因为您可能希望在生产中预编译所有这些静态内容。

您能告诉我更多您所说的“因为您可能希望在生产中预编译所有这些静态内容”是什么意思吗?我应该不将任何图像放在css中吗?静态图像一点问题都没有。但是,如果我没弄错,您可以要替换此图像,因此它不应是(如果已预编译)静态文件的一部分。如果您想阅读有关预编译的内容,请参阅。除此之外,即使您真的要在样式表中动态替换图像,客户端也无法缓存您的css,因此我认为将其放在视图中是正确的方法。
<%= image_tag @logo.image_url.to_s %>
section#header {
height: 220px;
position: relative;
h1 {
    background-image: url('<%= asset_path 'logo.png' %>');
    position: absolute;
    width: 412px;
    height: 188px;
    z-index: 999;
}