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 6887941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:56:49+00:00 2026-05-27T05:56:49+00:00

I have a model (share) in which I save who can edit a lesson.

  • 0

I have a model (share) in which I save who can edit a lesson.
It is separated from the user model, and from the lesson model.
The data is currently saved as

|share_id | lesson_id | shared_ids |
|    2    |     23    | "45,66,21" |

Where “shared_ids” are the user ids that can edit the lesson

I would like to split it into

|share_id | lesson_id | shared_ids |
|    2    |     23    |    "45"    |
|    3    |     23    |    "66"    |
|    4    |     23    |    "21"    |

I have managed to split the shared_ids, but it is currently saved as one array inside the table :

|share_id | lesson_id |   shared_ids   |
|    2    |     23    | "45","66","21" |

Thanks for your help.

—- Edit —-
The Share class looks like that:

class Share < ActiveRecord::Base
  attr_accessible :shared_token, :shared_ids
  belongs_to :lesson

  attr_reader :shared_token
  serialize :shared_ids
  # @Todo: save each seperately #
  def shared_token=(ids)
    self.shared_ids = ids.split(",")
  end
end

—- Edit 2 —–
The form for shared_token in the lesson view:

<%= f.fields_for :shares do |builder| %>
  <%= builder.label :shared_token, "Type the user names you wish to share the lesson with:" %>
  <%= builder.text_field :shared_token, "data-pre" => @shared_ids %>
<% end %>
  • 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-05-27T05:56:49+00:00Added an answer on May 27, 2026 at 5:56 am

    Since Shares are children of Lessons, I think you might want to write a methed in your Lesson model that would iterate through the ids in a list (which you’ve already figured out how to generate) and create a Share for each id. something like…

    def build_shares_from_list(ids)
        ids.each do |id|
            @share = self.shares.build({:share_ids => id})
            @share.save
        end
    end
    

    Then call that from your Lesson controller, and point your form to the appropriate controller action.

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

Sidebar

Related Questions

I'm currently working on redesigning an application which is building a model from input
I currently have an iOS app that can 'bootstrap' it's database from a bunch
I have model Foo which has field bar. The bar field should be unique,
In my controller I have model operations that can return empty results. I've setup
I have a model being populated by my data layer and then I have
I have a Campaign model which has_many Calls, Emails, and Letters. For now, these
Here's my situation.. Suppose you have the following model entities, which represent single tables
I have a controller which has several methods which should all share common informations.
I am designing a data model for tourism-site. I have a table for places
I have a custom model class which contains a decimal member and a view

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.