Reputation: 7400
I just had a general doubt which I wanted to clear wrt Rails. I am currently working on Rails 2.0.2 for project specific purposes and I had a doubt especially related to this version of Rails.
I did a basic scaffold in my rails app on "posts".. something like ruby script/generate scaffold posts
. This created a posts.html.erb file for me in my app/views/layouts .. I have seen in many blogs/screen casts they say when we add Javascript(JS) files like for e.g. those implementing jquery etc. we need to make include the necessary files in our "application.html.erb"
files.. Now since I don't have anything exactly coined as such in my app.. does Rails by default take my posts.html.erb
in my layouts as the equivalent application.html.erb
..?
Or is that I need to explicitly create application.html.erb in my rails app?
My main concern behind this question is that would JS files be included in case if I have something like posts.html.erb
or is that.. it should be done only in the application.html.erb
..
Thank you..
Upvotes: 0
Views: 1596
Reputation: 33752
an app/views/layouts/application.html.erb file should have been generated for you when you did "rails new ProjectName"
make sure you have one... it controls the general layout of your web-site.
Upvotes: 0
Reputation: 9748
does Rails by default take my posts.html.erb in my layouts as the equivalent application.html.erb..?
Yes. For the PostsController it will (by convention) take layouts/posts.html.erb
as the overall layout template.
If you remove this file it will fall back to the layouts/application.html.erb
layout.
My main concern behind this question is that would JS files be included in case if I have something like posts.html.erb or is that.. it should be done only in the application.html.erb..
You would have to include all necessary JS/CSS in each layout, as there is no layout inheritance.
If you want multiple layouts you can refactor out sections into partials (eg: for the <head>
bit).
Upvotes: 0
Reputation: 124469
For a PostsController
, Rails will first look for an app/views/layouts/posts.html.erb
file. Only if it doesn't find this controller-specific layout will it then fall back to app/views/layouts/application.html.erb
.
Upvotes: 1