api/news_controller.rb内でNews.allなどNewsモデルのActiveRecordの機能を使えません。機能を使えるようになる解決方法を教えていただきたいです。ちなみにrails consoleや他のControllerではNewsモデルのActiveRecordの機能は使えます。
log
1 Started GET "/api/news" for 127.0.0.1 at 2018-12-02 08:25:40 +0900 2Processing by Api::NewsController#index as HTML 3Module 4Class 5Completed 500 Internal Server Error in 30ms (ActiveRecord: 2.0ms) 6NoMethodError (undefined method `all' for Api::News:Module): 7app/controllers/api/news_controller.rb:10:in `index'
controllers/api/news_controller.rb
ruby
1module Api 2 class NewsControllr < ApplicationController 3 def index 4 logger.debug News.class 5 logger.debug User.class 6 @news = News.all 7 render json: @news 8 end 9 end 10end
models/news.rb
ruby
1class News < ApplicationRecord 2end
models/users.rb
ruby
1class Users < ApplicationRecord 2end
config/routes.rb
Rails.application.routes.draw do namespace :api, format: :json do resources :news, only: :index do end end
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。