Reputation: 11
I have a problem with the content_for in RoR, I have a remote call to the controller it contains the javascript update.js.erb render a partial _update.html.erb and within the partial content_for where there is the inside of it there is a javascript that needs to be added to the Head of the html page
controller
def uploadimage
respond_to do |format|
format.js
end
end
update.js.erb
$('#reloadimage').html("<%= escape_javascript( render 'users/crop' )%>");
partial _crop.html.erb
<% content_for(:head1) do %>
<%= stylesheet_link_tag "jquery.Jcrop" %>
<%= javascript_include_tag "jquery.Jcrop.min" %>
<script type="text/javascript" charset="utf-8">
$(function() {
$('#cropbox').Jcrop({
onChange: update_crop,
onSelect: update_crop,
setSelect: [0, 0, 500, 500],
aspectRatio: 1
});
});
</script>
<% end %>
layaout application.html.erb
<head>
....
<%= yield :head1 %>
....
</head>
Upvotes: 1
Views: 1015
Reputation: 91513
This is not going to work. Remember you are manipulating HTML on the client side, the layout is already rendered.
Add your changes to the head in the update.js.erb
:
$("head").append(.....);
Upvotes: 1