Home Ask Login Register

Developers Planet

Your answer is one click away!

T.Aloufi 2 weeks ago

Index.js.erb file not working in rails 5.1

I am following a tutorial from devfactor.com. It's called "Let's Build: Instagram with Rails." The author is using AJAX and js files in the tutorial. When added a file called "Index.js.erb", it showed many errors in my server. Error:

ActionView::Template::Error (Missing partial posts/_posts, application/_posts wi
th {:locale=>[:en], :formats=>[:js, :html], :variants=>[], :handlers=>[:raw, :er
b, :html, :builder, :ruby, :coffee, :jbuilder]}. Searched in:
  * "C:/Users/alouftur0/Rails/Photogram/app/views"
  * "C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/kaminari-core-1.0.1/app/views"
  * "C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/devise-4.3.0/app/views"
    1: $('#posts').append("<%= escape_javascript(render 'posts')%>");
    2: $('#paginator').html("<%= escape_javascript(link_to_next_page(@posts, 'LO
AD MORE', remote: true, id: 'load_more'))%>");
    3: if (!$('#load_more').length) { $('#paginator').remove(); }

app/views/posts/index.js.erb:1:in `_app_views_posts_index_js_erb___1182481000_10

Here are the files:


<!DOCTYPE html>
    <%= csrf_meta_tags %>

    <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>

  <%= render 'posts/navbar' %>
  <% flash.each do |key, value| %>
    <div class="alert alert-<%= key %>"><%= value %></div>
  <% end %>
  <%= yield %>


<% @posts.each do |post| %>
  <%= render 'post', post: post %>
<% end %>
<div class="text-center" id="paginator">
  <%= link_to_next_page @posts, 'LOAD MORE', remote: true, id: 'load_more' %>


Michael Yurkovetc 2 weeks ago

You need to render partial such as

$('#posts').append("<%= escape_javascript(render @posts) %>");

Post Status

Asked in 2 weeks ago
Viewed 3,147 times
Voted 12
Answered 1 times


Leave an answer

Quote of the day: live life