CSS和JS没有在rails上的一个控制器ruby中加载两个动作

时间:2015-10-29 16:13:25

标签: html css ruby-on-rails ruby

来自家庭控制器中索引操作的index.html.erb页面可以很好地加载视图中链接的所有css和js,例如.html.erb但是当通过'link_to'在同一页面中调用另一个操作时,所有js和css丢失了。尽管在针对ex的新操作中提供了与css和js相同的链接:contact.html.erb视图在家庭控制器中被调用为“联系人”操作。

如何将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>

1 个答案:

答案 0 :(得分:0)

我通过在application.html.erb / home.html.erb中使用stylesheet_link_tag和javascript_include_tag来解决此问题,以包含不同的资源,而不是使用包含它的html方式。