Josh Goldman


3,610 Experience
35 Lessons Completed
0 Questions Solved


I am in the process of building a rails app and I am unsure if I need to separate my front facing mostly static website from my web application. I see lots of example of sites having there front facing sites at while their web apps are at

What considerations should I make in this decisions and what are the pros/cons?

Posted in Scope has_many relationship

I have four models

  1. Problem
  2. User
  3. Question
  4. Reply
class Problem < ApplicationRecord
  has_many :questions
class User < ApplicationRecord
  has_many :questions
  has_many :replies
class Question < ApplicationRecord
  belongs_to :problem
  belongs_to :user
  has_many :replies
class Reply < ApplicationRecord
  belongs_to :user
  belongs_to :question

The Reply model has an attribute answer:boolean, a question can have multiple replies and those replies can be marked as an answer to their associated question.

I am trying to create two scopes on the Question model one for answered questions and one for unanswered questions.

answered -> has at least one reply that was marked as an answer (boolean is true)
unanswered -> has no replies marked as an answer (boolean is true)

I would like to be able to use the scopes like this:


Also I will be displaying the user associated with the questions as well as the replies associated with the questions and the users associated with those replies, so think I need to use some type of "includes" statement so that I don't create N + 1 query.

I am stuck on how to achieve this?