Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6974645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:15:54+00:00 2026-05-27T17:15:54+00:00

I have groups ( Group model) in my app, which represent groups of people.

  • 0

I have groups (Group model) in my app, which represent groups of people.
I want each group to have its own forum.

Should I just have the forum id in the groups table? It doesn’t feel right. If I did it myself, the forum would have a polymorphic association to a “forumable” element (groups in this case, but I have other models that would need a forum).

Any opinions on what I should do? Modify the gem to fit my needs, or just have the forum_id in my models that need a forum? Or another solution maybe?

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:15:55+00:00Added an answer on May 27, 2026 at 5:15 pm

    I’m the guy who started Forem (its the volunteers who did most of the hard work, though!), I think I can answer this question.

    If you want only certain groups to have access to one and only one forum then you can put the forum_id field on the groups table and do it that way. What you can do then is override the can_read_forem_forum? method in your User model to perform a permission check for that user:

    def can_read_forem_forum?(forum)
      groups.where(:forum_id => forum.id).any?
    end
    

    This is used in Forem’s ability model to determine whether or not a person can access a forum. What this method is going to do is that it will only return groups for that user that have link that specific forum. If there are any, then it’s known that the user can access that forum.

    Now if you’re going the other route where a group may have access to many forums, well then you’d define a joins table between groups and forem_forums (called forum_groups) and define it as an association in your Group model like this:

    has_many :forum_groups
    has_many :forums, :through => :forum_groups, :class_name => "Forem::Forum"
    

    You would need to also define a new model inside your application for this forum_groups association, it would be called ForumGroup and go a little like this:

    class ForumGroup < ActiveRecord::Base
      belongs_to :forum, :class_name => "Forem::Forum"
      belongs_to :group
    end
    

    We’re doing it this way so you have an easy way to manage the associations between forums and groups. If you did has_and_belongs_to_many, it generally only provides a gigantic pain in the ass when you want to delete one specific record from that join table.

    Now, with that all nicely set up, the method you want to define in your User model is this one:

    def can_read_forem_forum?(forum)
      groups.joins(:forums).where("forem_forums.id = ?", forum.id).any?
    end
    

    Same thing, except this time we find all the groups that are linked to a specific forum through that association we set up earlier. This will do an INNER JOIN on the forum_groups table, and then another on the forem_forums table, getting the data required.

    I hope this helps you, and thanks for using Forem!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rails 2.1 app with order which belongs to group. I want
I have an app with 2 models: Product and Photo , each of which
I have the following model in my Django app: class Group(models.model): name=models.CharField(max_length=30) users=Models.ManyToManyField(User) In
I have (my own) java App to control and monitor a model railway. Naturally
I have the following :has_many, :through association for my models: Group Model: has_many :group_users
I am using Rails 3. I have a Product model and a Group model
I have the following model structure: class Group < ActiveRecord::Base has_many :group_products, :dependent =>
I have the following code to generate a table listing brand/model/submodel/style for a group
I have 4 models in my project. Which are : class Company(Group): address_1 =
I have a problem - i can't compile SqlCipher. I'm using this http://groups.google.com/group/sqlcipher/browse_thread/thread/55c6296b56bf4533/c792bbec6df7d4f4?tvc=2#c792bbec6df7d4f4 instructions

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.