#前提
現在ruby on railsのアプリに無限スクロールを実装しようとしています。
ですが、下記エラーが出ており、解決できていません。
お力添えをお願いいたします。
バージョンは ruby 2.4.2 rails 4.2.10になります。
参考URL
参考url はてブロ
github
#起こっているエラー
undefined method `render' for #<#<Class:0x00007faf273341d0>:0x00007faf2ba1d7b8>
#コード
ruby
1#index.html.erb 2 3<table id="titles"> 4 5 <tbody class="page"> 6 <%= render @titles %> 7 8<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script> 9 10<script src="js/jquery.infinitescroll.min.js"></script> 11 12 </tbody> 13 14</table> 15 16<%= paginate @titles %>
ruby
1#_title.html.erb 2 3<tr class= "title"> 4 <% @titles.each do |title|%> 5 6 <p><%= title.titlename %></p> 7 8 <% end %> 9</tr>
javascript
1 2#index.js.erb 3 4#エラーの箇所 5$("#titles").append("<tbody class='page'><%= j render(@titles) %></tbody>"); 6
ruby
1#titles_controller.rb 2 3class TitlesController < ApplicationController 4 5 def index 6 @titles = Title.page(params[:page]).per(10) 7 end 8end
javascript
1 2#application.js 3 4//= require jquery 5//= require jquery_ujs 6//= require_self 7//= require turbolinks 8//= require_tree . 9
ruby
1 2#gemfile 3 4source 'https://rubygems.org' 5 6git_source(:github) do |repo_name| 7 repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") 8 "https://github.com/#{repo_name}.git" 9end 10 11 12# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 13gem 'rails', '~> 4.2.10' 14# Use sqlite3 as the database for Active Record 15gem 'sqlite3' 16# Use Puma as the app server 17gem 'puma', '~> 3.7' 18# Use SCSS for stylesheets 19gem 'sass-rails', '~> 5.0' 20# Use Uglifier as compressor for JavaScript assets 21gem 'uglifier', '>= 1.3.0' 22# See https://github.com/rails/execjs#readme for more supported runtimes 23# gem 'therubyracer', platforms: :ruby 24 25# Use CoffeeScript for .coffee assets and views 26gem 'coffee-rails', '~> 4.2' 27# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks 28gem 'turbolinks', '~> 5' 29# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 30gem 'jbuilder', '~> 2.5' 31# Use Redis adapter to run Action Cable in production 32# gem 'redis', '~> 4.0' 33# Use ActiveModel has_secure_password 34# gem 'bcrypt', '~> 3.1.7' 35gem 'jquery-rails' 36# Use Capistrano for deployment 37# gem 'capistrano-rails', group: :development 38gem 'jquery-turbolinks' 39gem 'kaminari' 40group :development, :test do 41 # Call 'byebug' anywhere in the code to stop execution and get a debugger console 42 gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] 43 # Adds support for Capybara system testing and selenium driver 44 gem 'capybara', '~> 2.13' 45 gem 'selenium-webdriver' 46end 47 48group :development do 49 # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. 50 gem 'web-console', '>= 3.3.0' 51 gem 'listen', '>= 3.0.5', '< 3.2' 52 # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 53 gem 'spring' 54 gem 'spring-watcher-listen', '~> 2.0.0' 55end 56 57# Windows does not include zoneinfo files, so bundle the tzinfo-data gem 58gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 59
#行なった施策
色々調べた結果、stack over flowに同じ質問がありました。
index.js.erbファイルの置き場所が悪いという回答でした。その回答内にはviewの下に配置しなさいと書かれていましたが、viewの下に配置しても解決しません。
#質問事項
1.renderがundefinedになる理由をお教えください。
2.renderを使わないで無限スクロールを実装できる方法がございましたらお教えください。
ご回答は1番だけでも結構です。
何卒何卒よろしくお願いいたします。
あなたの回答
tips
プレビュー