我是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时,我收到了这个错误。 root_path &GT;
没有路线匹配{:action =&gt;“show”,:controller =&gt;“users”}
app / views / layouts / application.html.erb:14:in _app_views_layouts_application_html_erb__2507795966534755030_70012866854080'
答案 0 :(得分:0)
尼尔,
尝试以下方法:
current_page?(url_for(:controller => 'users', :action => 'show'))