views:

30

answers:

1

I'm trying to implement some javascript on a rails page using content_for and yield.

I'm new to rails and learning rails3.

In my applicatoin.html.erb file, I have

<%= yield :javascript %>

and in my index page, i've got

<% content_for :javascript do %>
    <%= javascript_tag do %>
        alert('test')
   <% end %gt;
<% end %>

pretty basic stuff, and yet nothing is showing up in the requested page. Any suggestions?

A: 

I've noticed in Rails 3 that any script tags included on any page other than a layout are stripped, along with its contents, before the page renders. I need to look up the specifics of it (so I don't have a link), but I would bet that's your problem.

The easy fix is to add your script tags on the layout page you're using and add the content of your script in the content_for in question.