rj487
rj487

Reputation: 4634

Rails generate a new layout file

I felt confused about the Rails layout. I have the home and video page, and I want to include their css and js relatively.

Therefore, after I used scaffold to create video, I created video.css and video.js.

Furthermore, I created a file in view/layouts/video_layout.html.erb and put the following code into it.

<!DOCTYPE html>
<html>
  <head>
    <title>Video</title>
    <%= csrf_meta_tags %>
    <%= stylesheet_link_tag    'video', media: 'all', 'data-turbolinks-track': 'reload' %>
    <%= javascript_include_tag 'video', 'data-turbolinks-track': 'reload' %>
  </head>

  <body>
    VIDEO BEGIN
    <%= yield %>
    VIDEO END
  </body>
</html>

I thought it will include only video.css and video.js. However, when I accessed localhost:3000/videos, the video page was still in original condition (no VIDEO BEGIN and VIDEO END )

Upvotes: 1

Views: 2301

Answers (1)

kirqe
kirqe

Reputation: 2470

add the following line to app/controllers/videos_controller.rb

layout "video_layout"

eg

class VideosController < ApplicationController
  layout "video_layout"

  def index
  end

  ....
end

also check this http://api.rubyonrails.org/classes/ActionView/Layouts.html

Upvotes: 4

Related Questions