Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.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
如何在xxx.css.scss中使用xxx.rb中的元素?_Css_Ruby On Rails_Ruby_Ruby On Rails 3 - Fatal编程技术网

如何在xxx.css.scss中使用xxx.rb中的元素?

如何在xxx.css.scss中使用xxx.rb中的元素?,css,ruby-on-rails,ruby,ruby-on-rails-3,Css,Ruby On Rails,Ruby,Ruby On Rails 3,这是“.rb”文件: 我希望背景图像显示@random\u image,但我不知道url()中应该有什么 谢谢 简而言之,您不能通过.css动态更改背景,因为它只加载一次,但您可以在布局文件中指定样式。检查类似的情况。在这种情况下,确实不容易。 class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may wan

这是“.rb”文件:

我希望
背景图像
显示
@random\u image
,但我不知道
url()
中应该有什么


谢谢

简而言之,您不能通过.css动态更改背景,因为它只加载一次,但您可以在布局文件中指定样式。检查类似的情况。

在这种情况下,确实不容易。
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception

def bg
  @images  = ["bg1.jpg", "bg2.jpg", "bg3.jpg", "bg4.jpg", "bg5.jpg","bg6.jpg","bg7.jpg","bg8.jpg"]
  @random_no = rand(8)
  @random_image = @images[@random_no]
end

end
#welcome
{
  background-image:url();
}