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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:00:31+00:00 2026-06-18T05:00:31+00:00

Here are my models: class ThesisGroup < ActiveRecord::Base belongs_to :course has_and_belongs_to_many :students attr_accessible :code,

  • 0

Here are my models:

class ThesisGroup < ActiveRecord::Base
  belongs_to :course
  has_and_belongs_to_many :students

  attr_accessible :code, :title, :course_id
end

class Student < ActiveRecord::Base
  has_and_belongs_to_many :thesis_groups

  attr_accessible :email, :lastnames, :names
end

class CreateThesisGroupStudentJoinTable < ActiveRecord::Migration  
  def change
    create_table :thesis_groups_students, :id => false do |t|
      t.integer :thesis_group_id
      t.integer :student_id
    end
  end
end

And in my controller, for the editing of ThesisGroups:

def update
    @thesis_group = ThesisGroup.find(params[:id])

    respond_to do |format|
      if @thesis_group.update_attributes(params[:thesis_group])
        format.html { redirect_to @thesis_group, notice: 'Thesis group was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @thesis_group.errors, status: :unprocessable_entity }
      end
    end
  end

In my View, I need to able to see N drop down lists; 1 for each student in the relationship with this current ThesisGroup.

I tried the following but get an error, undefined method map for #<ThesisGroup:0x007f76b8c9d4d0>:

<div class="control-group">
  <%= f.label :student %>
  <div class="controls">
    <%= f.collection_select 'student_ids', @thesis_group, :id, :names %>
  </div>
</div>

I need to have N select elements for students and when editing this form have the previously selected elements displayed as selected. Does Rails have some way of handling this?

Can I iterate through the student_ids collection and something like:

<%= student_ids.each do |s| %>
  generate html select element with 's'
<% 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-06-18T05:00:32+00:00Added an answer on June 18, 2026 at 5:00 am

    You’ll need accepts_nested_attributes_for :students in your ThesisGroup model.

    <%= field_set_tag 'Alumnos' do %>
      <%= f.fields_for :students do |student| %>
        <%= student.label :name, 'Student' %>
        <%= student.collection_select :student_id, Student.all, :id, :name %>
      <% end %>
    <% end %>
    

    Edit: I’m suddenly not too sure about the parameters in collection_select either 🙁

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

Sidebar

Related Questions

Here are my models: class BillingProfile < ActiveRecord::Base belongs_to :student attr_accessible :cost end class
Here's my code: Models: class Article < ActiveRecord::Base attr_accessible :title, :author, :content, :imageable_attributes has_one
Here are my models: class Deck < ActiveRecord::Base belongs_to :game has_many :deck_cards end class
Here my models: class User < ActiveRecord::Base has_many :bookmarks end class Topic < ActiveRecord::Base
So I have two models here: class Screen < ActiveRecord::Base belongs_to :user validates :screen_size,
Hi (huge Rails newbie here), I have the following models: class Shop < ActiveRecord::Base
Hey, need a little help here. I have two models: class User < ActiveRecord::Base
Here are my models: class Project < ActiveRecord::Base has_many :gs_collectors, dependent: :destroy class GsCollector
Here is my models: class User < ActiveRecord::Base has_one :worker, :class_name => 'Worker', :foreign_key
Imagine these models: class User belongs_to :profile # has email here end class Profile

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.