Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails content_for does not get executed when doing render?

So I have a content_for inside my view for logging in and in the sessions controller, I have render :new 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 how my content_for look like

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

Is there a work around to make sure that the above code gets executed when I do render?

like image 477
denniss Avatar asked Jan 11 '12 18:01

denniss


1 Answers

My guess would be that you're not including the content_for anywhere. In app/views/layouts/application.html.erb (or whichever layout you're using for this page) make sure you've got something like the following:

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

When you pass a block to content_for, the contents of the block are stored to be used elsewhere. The call to content_for without a block will then insert that stored content.

See the docs for content_for for more info.

like image 191
Emily Avatar answered Sep 22 '22 11:09

Emily