gpt4 book ai didi

html - Rails current_page? View 上的 UrlGenerationError

转载 作者:太空宇宙 更新时间:2023-11-03 16:49:21 28 4
gpt4 key购买 nike

我是 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. 时遇到了这个错误。根路径>

No route matches {:action=>"show", :controller=>"users"}

app/views/layouts/application.html.erb:14:in _app_views_layouts_application_html_erb__2507795966534755030_70012866854080'

最佳答案

尼尔,

尝试以下操作:

current_page?(url_for(:controller => 'users', :action => 'show')) 

关于html - Rails current_page? View 上的 UrlGenerationError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26072392/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com