gpt4 book ai didi

html - CSS 和 JS 没有在一个 Controller 中加载两个 Action ruby​​ on rails

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

主 Controller 中索引操作的 index.html.erb 页面可以很好地加载 View 中链接的所有 css 和 js,即 .html.erb 但是当通过“link_to”在同一页面中调用另一个操作时,所有js和css丢失了。尽管指向 css 和 js 的相同链接在 ex 的新操作中可用:contact.html.erb View 在家庭 Controller 中调用“联系人”操作。

Controller 中的所有 Action 如何使用css和js?抱歉我的天真,因为我刚开始使用 RoR。

class HomeController < ApplicationController
def index
end

def contact
end

def generic
end

def elements
end
end


<!--"Application.html.erb"-->

<!DOCTYPE html>
<html>
<head>
<title>MiniProject</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
<script src="js/ie/html5shiv.js"></script>
<link rel="stylesheet" href="css/main.css" />
<link rel="stylesheet" href="css/ie8.css" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<header id="header" class="alt">
<h1><a href="index.html">Make</a>My Ride</h1>
<nav id="nav">
<ul>
<li><a href="index.html">Home</a></li>
<li>
<a href="#" class="icon fa-angle-down">Layouts</a>
<ul>
<li><%= link_to "Generic", home_generic_path%></li>
<li><%= link_to "Contact", home_contact_path%></li>
<li><%= link_to "Elements", home_elements_path%></li>
<li>
<a href="#">Submenu</a>
<ul>
<li><a href="#">Option One</a></li>
<li><a href="#">Option Two</a></li>
<li><a href="#">Option Three</a></li>
<li><a href="#">Option Four</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#" class="button">Sign Up</a></li>
</ul>
</nav>
</header>


<body>
<% if notice %>
<p class="alert alert-success"><%= notice %></p>
<% end %>
<% if alert %>
<p class="alert alert-danger"><%= alert %></p>
<% end %>
<%= yield %>
<!-- Scripts -->
<script src="js/jquery.min.js"></script>
<script src="js/jquery.dropotron.min.js"></script>
<script src="js/jquery.scrollgress.min.js"></script>
<script src="js/skel.min.js"></script>
<script src="js/util.js"></script>
<!--[if lte IE 8]><script src="assets/js/ie/respond.min.js"></script><![endif]-->
<script src="js/main.js"></script>

</body>
<!-- Footer -->
<footer id="footer">
<ul class="icons">
<li><a href="#" class="icon fa-twitter"><span class="label">Twitter</span></a></li>
<li><a href="#" class="icon fa-facebook"><span class="label">Facebook</span></a></li>
<li><a href="#" class="icon fa-instagram"><span class="label">Instagram</span></a></li>
<li><a href="#" class="icon fa-github"><span class="label">Github</span></a></li>
<li><a href="#" class="icon fa-dribbble"><span class="label">Dribbble</span></a></li>
<li><a href="#" class="icon fa-google-plus"><span class="label">Google+</span></a></li>
</ul>
<ul class="copyright">
<li>&copy; Untitled. All rights reserved.</li><li>Design: <a href="http://html5up.net">HTML5 UP</a></li>
</ul>
</footer>
</html>


<!--"Index.html.erb"-->
<html>
<body class="landing">
<div id="page-wrapper">
<!-- Banner -->
<section id="banner">
<h2>Alpha</h2>
<p>Another fine responsive site template freebie by HTML5 UP.</p>
<ul class="actions">
<li><a href="#" class="button special">Sign Up</a></li>
<li><a href="#" class="button">Learn More</a></li>
</ul>
</section>

<!-- Main -->
<section id="main" class="container">

<section class="box special">
<header class="major">
<h2>Introducing the ultimate mobile app
<br />
for doing stuff with your phone</h2>
<p>Blandit varius ut praesent nascetur eu penatibus nisi risus faucibus nunc ornare<br />
adipiscing nunc adipiscing. Condimentum turpis massa.</p>
</header>
<span class="image featured"><img src="images/pic01.jpg" alt="" /></span>
</section>

<section class="box special features">
<div class="features-row">
<section>
<span class="icon major fa-bolt accent2"></span>
<h3>Magna etiam</h3>
<p>Integer volutpat ante et accumsan commophasellus sed aliquam feugiat lorem aliquet ut enim rutrum phasellus iaculis accumsan dolore magna aliquam veroeros.</p>
</section>
<section>
<span class="icon major fa-area-chart accent3"></span>
<h3>Ipsum dolor</h3>
<p>Integer volutpat ante et accumsan commophasellus sed aliquam feugiat lorem aliquet ut enim rutrum phasellus iaculis accumsan dolore magna aliquam veroeros.</p>
</section>
</div>
<div class="features-row">
<section>
<span class="icon major fa-cloud accent4"></span>
<h3>Sed feugiat</h3>
<p>Integer volutpat ante et accumsan commophasellus sed aliquam feugiat lorem aliquet ut enim rutrum phasellus iaculis accumsan dolore magna aliquam veroeros.</p>
</section>
<section>
<span class="icon major fa-lock accent5"></span>
<h3>Enim phasellus</h3>
<p>Integer volutpat ante et accumsan commophasellus sed aliquam feugiat lorem aliquet ut enim rutrum phasellus iaculis accumsan dolore magna aliquam veroeros.</p>
</section>
</div>
</section>

<div class="row">
<div class="6u 12u(narrower)">

<section class="box special">
<span class="image featured"><img src="images/pic02.jpg" alt="" /></span>
<h3>Sed lorem adipiscing</h3>
<p>Integer volutpat ante et accumsan commophasellus sed aliquam feugiat lorem aliquet ut enim rutrum phasellus iaculis accumsan dolore magna aliquam veroeros.</p>
<ul class="actions">
<li><a href="#" class="button alt">Learn More</a></li>
</ul>
</section>

</div>
<div class="6u 12u(narrower)">

<section class="box special">
<span class="image featured"><img src="images/pic03.jpg" alt="" /></span>
<h3>Accumsan integer</h3>
<p>Integer volutpat ante et accumsan commophasellus sed aliquam feugiat lorem aliquet ut enim rutrum phasellus iaculis accumsan dolore magna aliquam veroeros.</p>
<ul class="actions">
<li><a href="#" class="button alt">Learn More</a></li>
</ul>
</section>

</div>
</div>

</section>

<!-- CTA -->
<section id="cta">

<h2>Sign up for beta access</h2>
<p>Blandit varius ut praesent nascetur eu penatibus nisi risus faucibus nunc.</p>

<form>
<div class="row uniform 50%">
<div class="8u 12u(mobilep)">
<input type="email" name="email" id="email" placeholder="Email Address" />
</div>
<div class="4u 12u(mobilep)">
<input type="submit" value="Sign Up" class="fit" />
</div>
</div>
</form>

</section>
</div>
</body>
</html>



<!--"Contact.html.erb"-->

<html>
<body>
<div id="page-wrapper">

<!-- Main -->
<section id="main" class="container 75%">
<header>
<h2>Contact Us</h2>
<p>Tell us what you think about our little operation.</p>
</header>
<div class="box">
<form method="post" action="#">
<div class="row uniform 50%">
<div class="6u 12u(mobilep)">
<input type="text" name="name" id="name" value="" placeholder="Name" />
</div>
<div class="6u 12u(mobilep)">
<input type="email" name="email" id="email" value="" placeholder="Email" />
</div>
</div>
<div class="row uniform 50%">
<div class="12u">
<input type="text" name="subject" id="subject" value="" placeholder="Subject" />
</div>
</div>
<div class="row uniform 50%">
<div class="12u">
<textarea name="message" id="message" placeholder="Enter your message" rows="6"></textarea>
</div>
</div>
<div class="row uniform">
<div class="12u">
<ul class="actions align-center">
<li><input type="submit" value="Send Message" /></li>
</ul>
</div>
</div>
</form>
</div>
</section>
</div>
</body>
</html>

最佳答案

我通过在 application.html.erb/home.html.erb 中使用 stylesheet_link_tag 和 javascript_include_tag 来包含不同的 Assets 而不是使用包含它的 html 方式解决了这个问题。

关于html - CSS 和 JS 没有在一个 Controller 中加载两个 Action ruby​​ on rails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33419399/

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