Полная ошибка сервера:
LoadError (Unable to autoload constant Board_Game, expected /Users/michellegarcia/coding_personal_projects/board_game_app/app/models/board_game.rb to define it):
app/controllers/api/board_games_controller.rb:3:in `index'
У меня здесь ошибка орфографии или заглавные буквы, но я не могу найти где.Я хочу console.log всех Board_Games
, которые я вручную добавил в свою базу данных, чтобы я перечислил их.
controller
class Api::BoardGamesController < ApplicationController
def index
render json: Board_Game.all
end
def show
render json: @board_games
end
def create
board_game = Board_Game.new
if board_game.save
render json: board_game
else
render json: board_game.errors
end
end
def update
if @board_game.update(board_game_params)
render json: @board_game
else
render_error(@board_game)
end
end
def destroy
@board_game.destroy
end
private
# def set_board_game
# @board_game = Board_Game.find(params[:id])
# end
def board_game_params
params.require(:board_game).permit(
:title,
:min_players,
:max_players,
:base_game,
:time_needed,
:company
)
end
end
модель
class BoardGame < ApplicationRecord
has_many :game_sessions, through: :game_session_games
has_many :rounds
end
маршруты
Rails.application.routes.draw do
mount_devise_token_auth_for 'User', at: 'api/auth'
namespace :api do
resources :board_games do
resources :game_sessions
end
#API ROUTES SHOULD GO HERE
end
#Do not place any routes below this one
get '*other', to: 'static#index'
end
компонент настольной игры
import React, { Component } from 'react';
import axios from 'axios';
//needs to do a call to the API to get the user's games from the user_board_game table
//if the user has no games, it needs to default to "You have no games. Add games to your library by clicking
//"Add Game""
//don't know if "Add Game" should be its own component or a conditional render.
//I want people to be able to add multiple games at once. Search Games. And have the option to add a game
//not on the list and auto-add it to their library. Also should have a checkbox for
//"I have played this game before" so their backlog can be easily sorted.
//if they've clicked on Add a Game, it should no longer render in the other component
class Games extends Component {
state = { games:[] }
//wasn't hitting debugger in componentDidMount because I had Component capitalized.
//then I was getting a 500 from my server because I didn't have resources :board_games in my routes.rb
//now getting 404
//this error "ActionController::RoutingError (uninitialized constant Api)" in server
//created an api folder in my controllers folder and moved my proprietery controllers inside it
//new error: app/controllers/api/board_games_controller.rb:15:
//syntax error, unexpected tINTEGER, expecting keyword_end
//got rid of 422 on line 15
//new error: LoadError (Unable to autoload constant
//Api::BoardGamesController, expected
///Users/michellegarcia/coding_personal_projects/board_game_app/app/controllers/api/board_games_controller.rb
// to define it):
// my has_many :blank didn't have colons in board_game.rb
componentDidMount() {
//runs when the user wants to add a game from the database
//link to more info and button to add the game if it's not in their library already
axios.get('/api/board_games')
.then(res => {
// const games = res.data;
console.log(res);
// this.setState({games});
})
}
getUserGames = () => {
//runs when component mounts and then goes to the Games_List Function
//checks if the user has games user.games? return { the list} : return {<h1>You have no games</h1>}
}
gamesList = () => {
//gives each game with a link to more info
}
render() {
return (
<div>
<h1>Games</h1>
<button>Add a Game</button>
<h3>Your Games</h3>
</div>
)
}
}
export default Games;
Я оставил в приложении все мои тупые заметки и неопределенную логику на случай, если вы можете предвидеть возникшую проблему или иметь какие-либо другие заметки,Я просто здесь, чтобы учиться, поэтому я открыт для критики по любому поводу.
Большинство других постов с похожим названием, похоже, имеют проблемы с одним и тем же именем класса в разных пространствах имен, чего у меня нетеще.