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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:40:37+00:00 2026-05-19T13:40:37+00:00

Hey I am stuck with my orientation in rails. I got a User model,

  • 0

Hey I am stuck with my orientation in rails.

I got a User model, a Course Model and a CourseEnrollment Model.

When I want to add a link in my Course Index View like

link_to 'join' CourseEnrollment.create(:course_id => course.id, :user_id => current_user)

Does this create method belong to my Model? I am confused because in my User Model I defined a method that uses role_assignments.create(.....). What is the difference between these 2 create methods? I cant use course_enrollments.create by the way. Thx for your time

  • 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-19T13:40:38+00:00Added an answer on May 19, 2026 at 1:40 pm

    I’m a bit confused as to what you’re asking, but I’ll try my best.

    (First of all, in your example, current_user should probably be current_user.id.)

    When you call CourseEnrollment.create, you are simply creating a new CourseEntrollment model with the specified attributes.

    Assuming that your User model has_many :role_assignments:

    When you call @role_assignments.create from within your User model, Rails automatically creates the association for you (e.g. sets the user_id to the id of the user). This doesn’t have to be done within the model itself, though:

    current_user.role_assignments.create(...) # automatically sets the association

    Assuming that your User model also has_many :course_enrollments, the following will create a CourseEnrollment model and automatically associate it with the current user:

    current_user.course_enrollments.create(...)

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

Sidebar

Related Questions

Hey I am stuck with 1 thing that I want a view like this
Hey, I've got this nice little piece of code, much like all the other
Hey, I'm really stuck with my project here... I need to know when any
Hey I am trying to make a dungeon crawler and I am stuck on
hey i followed a ruby on rails guide when i tried to run it
Hey all, I'm currently teaching myself Objective C and I'm kind of stuck. I'm
I'm pretty stuck here for what to do. I basically want to take all
Hey guys, hoping for some help with this :( been stuck on it for
Hey everyone and thanks for taking the time to help. I am stuck on
Hey Guys I'm working on Windows Mobile 5.0 (.Net 2.0) and I'm stuck at

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.