Rails content_for not executing while rendering?

So, I have content_forinside my view to log in and in the session controller, I have render :newit when the user does not enter valid credentials. However, when it does render :new, I get a black and white page without any css or js. This is what mycontent_for

<% content_for :head do %>
    <%= stylesheet_link_tag "user_sessions/new" %>
    <%= javascript_include_tag 'user_sessions/new.onready' %>
<% end %>

Is there any work to make sure the previous code will be executed when I do render?

+5
source share
2 answers

I assume that you do not include content_foranywhere. In app/views/layouts/application.html.erb(or any layout you use for this page), make sure you have something like the following:

<head>
  <!-- your regular head content goes here -->
  <%= content_for :head %>
</head>

content_for, . content_for .

. content_for.

+9
<head><%= content_for :head %></head>

,

<head><%= yield :head %></head>

, ,

: yield , :head - content_for, , . html u want

+3

All Articles