I want to get a list of all the reviews that belong to a, which belongs a category. I'm getting an error when trying to get a list of all the reviews in a JSON file (it's a API application): "/Code/Rails/videogame_reviews/app/controllers/reviews_controller.rb:6: syntax error, unexpected tIVAR, expecting '(' @reviews = @category.@game.reviews ^".
Could anybody explain why this is failing? @reviews = Reviews.all is working but shows all the reviews.
This the is ReviewsController
def index
@game = Game.find(params[:game_id])
@category = Category.find(params[:category_id])
@reviews = @category.@game.reviews
respond_to do |f|
f.html
f.json { render json: { category: @category, game: @game, reviews: @reviews} }
end
end
I've made a copy from the GamesController index which is working
def index
@category = Category.find(params[:category_id])
@games = @category.games
respond_to do |f|
f.html
f.json { render json: { category: @category, games: @games } }
end
end
Here is the Reviews model
class Review < ActiveRecord::Base
belongs_to :game
validates_presence_of :comment
end
This is the Game model
class Game < ActiveRecord::Base
belongs_to :category
has_many :reviews
validates_presence_of :title, :category
end
And this is the Category model
class Category < ActiveRecord::Base
validates_presence_of :name
has_many :games
end
Here is the routes for the reviews
resources :categories do
resources :games do
resources :reviews
end
end