Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Eric Kim
3,637 PointsHow to display different navbar only for index page?
On ruby, if you place your navbar on application.html.erb, it displays on every page, however what I really want to do is, displaying different style of navbar only for index page, not for other pages (like: about, FAQ, etc, <-application.html.erb)
How can I display different style of navbar only for index page? while putting common navbar on application.html.erb for other pages?
1 Answer
Mark Campbell
4,434 PointsThis may not be best practice as I'm a bit of a novice, however to do something similar in my app I do the following:
- Create a new layout file in your app/views/layouts folder such as home.html.erb
- In that layout file, include all the code you'd usually include in application.html.erb - except replace the navbar with the navbar you'd like to see on the index page.
- If you don't have a controller for pages, you'll need to create one - mine is pages_controller.rb
- Add some code to the controller to use the new layout you created, for example:
def home
respond_to do |format|
format.html { render :layout => 'home' }
end
end