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

  • Home
  • SEARCH
  • 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 8385205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:36:37+00:00 2026-06-09T17:36:37+00:00

I am looking to share lessons between users in a rails application. User A

  • 0

I am looking to share lessons between users in a rails application. User A has created some lessons and would like to share it with user B & C. User A creates a lesson, adds users B & C to the lesson and they now can see the lesson. My problem is how I can get the shared lessons to appear in users B & C shared page? Each lesson belongs to a notebook.

notebook.rb

belongs_to :user
has_many :lessons, :dependent => :destroy

lesson.rb

belongs_to :notebook
has_many :shareships
has_many :users, through: :shareships, dependent: :destroy
attr_reader :user_tokens
accepts_nested_attributes_for :shareships, :reject_if => lambda { |a| a[:user_ids].blank? }
scope :shared, lambda { where('shared_ids = ?') 

user.rb

has_many :notebooks, dependent: :destroy 

shareship.rb

belongs_to :lesson
belongs_to :user

lessons_controller.rb

class LessonsController < ApplicationController
  before_filter :authorize, :find_notebook
  load_and_authorize_resource :through => :notebook, :except => [:public]
  respond_to :html, :js, :json 


  def create
    @lesson = @notebook.lessons.build(params[:lesson])
    @lesson.user_id = current_user.id
    flash[:notice] = 'lesson Added!.' if @lesson.save
    respond_with(@lesson, :location => notebook_lessons_path)
  end


    def shared
      @user = current_user
      @shared = @notebook.lessons
    end
end

I have setup the many to many association between users and lessons so users can add other users to a lesson but I am trying to figure out how to list the lessons for the shared users. Any ideas how I can get this to work? I am having trouble setting it up and my controller and view.

  • 1 1 Answer
  • 0 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-06-09T17:36:39+00:00Added an answer on June 9, 2026 at 5:36 pm

    I would do something like this

    notebook.rb

    has_many :lessons
    belongs_to :user
    

    lesson.rb

    belongs_to :notebook
    has_many :shareships
    has_many :users, through: :shareships, dependent: :destroy # shared users of this lesson, not the owner
    

    user.rb

    has_many :notebook # the user will go through the notebook to get the lesson he owns
    has_many :shareships
    has_many :lessons, through: :shareships, dependent: :destroy # this would be only the shared lessons he has access to
    

    shareship.rb

    belongs_to :lesson
    belongs_to :user
    

    A user would have access the lesson he owns via

    /:user_id/notebooks/:notebook_id/lesson/:lesson_id 
    # lessons = user.notebooks[:notebook_id].lessons
    

    and he would have access to the lessons shared with him via

    /:user_id/shared_lessons/:lesson_id
    # shared_lessons = user.lessons
    

    The user does not have straight access to the lessons he owns, he needs to go through his notebooks. But he has straight access to the shared lessons.

    what do you think ?

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

Sidebar

Related Questions

I am looking for a quick way to share code snippets between developers. Visual
I am looking forward to implement NFC in iPhone. Can anyone share some sample
I was wondering if anyone would like to share with me how do you
Looking for good project methodologies.Anyone got some good reference links..want to share.
I'm looking for some kind of TELNET daemon for linux to share a single
When I was looking for ways to share resources (e.g. a DataSource) between Servlets,
I'm looking for schemes for application version or milestone naming . I'd like to
I'm looking for suggestions for ways to share Android app data between phones running
I am looking for the best way to effectively share chunks of data between
I am fairly new with WCF, I'm looking to share a service contract and

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.