简体   繁体   中英

Navigate with partials using rails and bootstrap

I'm using rails with Bootstrap. I have a basic page with navbar along the top. What I am struggling to achieve is how to define the targets for the options in the navbar as partials beneath this navbar.

I've trawled threads on here - finding things that don't quite marry up to the above, and followed the following tutorial: http://ruby.railstutorial.org/chapters/filling-in-the-layout#sec-partials ... which didn't work. No matter what I try, I end up with a link that simply directs to a whole new page.

My code as it stands (based on the above quoted tutorial)....

snippet from post_login.html.erb

            <ul class="nav navbar-nav">
              <li class="active"><%= link_to "P4 Sync", "p4syncpartial" %></li>
              <li><%= link_to "P4 Output", "p4outpartial" %></li>
            </ul>

<<<SNIP!!!>>>

    <div class="container">
    <%= yield %>
    </div>
</body>

routes.rb entry for one of the above tags:

  match '/p4syncpartial', to: 'authentication#_perforce', via: 'get'

And just for completeness, my placeholder authentication/_perforce.erb:

<p>This is a dummy P4 partial</p>

Can anyone point out where I am going wrong? Thank you :)

You're missing leading slash / in link_to url parameter:

<ul class="nav navbar-nav">
  <li class="active"><%= link_to "P4 Sync", "/p4syncpartial" %></li>
  <li><%= link_to "P4 Output", "/p4outpartial" %></li>
</ul>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM