【发布时间】:2023-03-12 08:10:01
【问题描述】:
我是 Rails 新手,我想要做的是:
当用户点击用户个人资料页面时,背景的样式会根据用户的喜好而改变。我正在使用current_page? 来识别我是否在显示页面(用户的个人资料)中。
有没有更好的方法来处理这个问题?
application.html.erb
<!DOCTYPE html>
<html class='no-js' lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title><%= full_title(yield(:title)) %></title>
<!-- Link foundation stylesheet -->
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "vendor/modernizr" %>
<%= csrf_meta_tags %>
<%= render 'layouts/shim' %>
</head>
<body>
<% if current_page?(controller: 'users', action: 'show') %>
<div style="background-attachment: fixed;
background-image: linear-gradient(<%= @user.first_bg_color %> 0%,
<%= @user.second_bg_color %> 100%);">
<% else %>
<div style="background-attachment: fixed;
background-image: linear-gradient(<%= current_user.first_bg_color %> 0%,
<%= current_user.second_bg_color %> 100%);">
<% end %>
<%= render 'layouts/offcanvas_start' %>
<%= yield %>
<%= render 'layouts/offcanvas_end' %>
</div>
<%= debug(params) if Rails.env.development? %>
<%= javascript_include_tag "application" %>
</body>
</html>
当我去 e.i. 时,我收到了这个错误。根路径 >
没有路由匹配 {:action=>"show", :controller=>"users"}
app/views/layouts/application.html.erb:14:in _app_views_layouts_application_html_erb__2507795966534755030_70012866854080'
【问题讨论】:
标签: html ruby ruby-on-rails-4 views