0

The controller:

class ProfilesController < ApplicationController
  def show
  end
end

When controller responds show action as JS, show.js.erb contains the following:

$('#main-content').html('<%= j( render( template: "profiles/show.html.erb" ) ) %>');

The problem is that I18n.t's scope get messed up when it attempts to fetch keys: ActionView::Template::Error (translation missing: en.profiles.show.html.erb.followers).

If I don't specify .html.erb part, it attempts to render show.js.erb which happens a infinite loop, so I must supply the html format.

What can I do?

Bruno Velasco
  • 135
  • 1
  • 6

1 Answers1

0

Extract the main part of profiles/show.html.erb into a partial:

profiles/_show.html.erb

then render as:

$('#main-content').html('<%= j raw render "profiles/show" %>') 

You can also render your profiles/show.html.erb the same way

<%= render 'show' %> <%# renders the partial %>
ilan berci
  • 3,883
  • 1
  • 16
  • 21
  • That did the trick, thanks! In fact I believe it doesn't make sense to render a template inside a view, which is show.js.erb. Partial makes more sense and it is working now. – Bruno Velasco Mar 24 '15 at 00:38