Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.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
Css ruby on rails上的随机头图像_Css_Ruby On Rails_Ruby - Fatal编程技术网

Css ruby on rails上的随机头图像

Css ruby on rails上的随机头图像,css,ruby-on-rails,ruby,Css,Ruby On Rails,Ruby,我使用下面的代码对分类页面标题中的图像进行随机化,但我真的不明白为什么这种方法不起作用 它在“…背景:url(“:expected”)”之后给了我这个错误无效的CSS,当我的建议起作用时是“。我将把它返回给未来读者的答案 你有.scss文件,所以ERB代码不起作用。但是试着像资产url(“随机化的头文件图像”)那样编写它。资产url是SASS的助手。我的建议起作用了。我将把它转回去给未来的读者一个答案 你有.scss文件,所以ERB代码不起作用。但是试着像资产url(“随机化的头\u图像”)那样

我使用下面的代码对分类页面标题中的图像进行随机化,但我真的不明白为什么这种方法不起作用

它在“…背景:url(“:expected”)”之后给了我这个错误
无效的CSS,当我的建议起作用时是“。我将把它返回给未来读者的答案

你有.scss文件,所以ERB代码不起作用。但是试着像
资产url(“随机化的头文件图像”)那样编写它。
资产url
是SASS的助手。

我的建议起作用了。我将把它转回去给未来的读者一个答案


你有.scss文件,所以ERB代码不起作用。但是试着像
资产url(“随机化的头\u图像”)那样编写它。
资产url
是SASS帮助程序。

好的,你有
.scss
,所以ERB代码不起作用。但是试着像
资产url(“随机化的头\u图像”)那样纠正它
。它会起作用。
资产url
是SASS助手。非常感谢,现在它工作得非常好。我将它添加为答案。感谢您确认您拥有
.scss
,因此ERB代码将不起作用。但请尝试像
资产url('randomized_header_image')那样对它进行更正
。它会起作用。
资产url
是SASS帮助程序。非常感谢,它现在工作得非常好。我将它添加为答案。感谢确认
<header id="necklace_header">
<h1>
  <%= @category.name %>
</h1>
</header>



<%= render "categories/table", products: @products %>



<% if current_user && current_user.admin? %>
    <%= link_to 'Edit', edit_category_path(@category) %> |
<% end %>

<%= link_to 'Back', root_path %>
#necklace_header {
    background: url(<%= randomized_header_image %>) no-repeat center center fixed;
    width: 100%;


    background-size: cover;  

    height: 360px;
    margin-bottom: 20px; 

}
module ApplicationHelper

    def randomized_header_image
        images = ["assets/foo.jpg", "assets/random.jpg", "assets/super_random"]
        images[rand(images.size)]
    end

end