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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:24:51+00:00 2026-06-14T05:24:51+00:00

I have a form with two collection_select fields, the first one is an easy

  • 0

I have a form with two collection_select fields, the first one is an easy one, it just gets a model named courses, which shows the course name, and of course returns the id of the selected course, the second is the one Im having problems with, its a collection_select of the similar courses a course may have.

The courses model:

class Course < ActiveRecord::Base
  extend FriendlyId
  friendly_id :name, use: :slugged 
  attr_accessible :code, :credits, :name, :description, :active

  has_many :similars, dependent: :destroy
  has_many :similar_courses, through: :similars, source: :similar

end

The similar model:

class Similar < ActiveRecord::Base
  attr_accessible :course_id, :similar_id

  belongs_to :course
  belongs_to :similar, class_name: "Course"

  validates :similar_id, presence: true
  validates :course_id, presence: true

end

this is the homologate model, the thing with this model is that a course must be approved or rejected if one wants to transfer classes and stuff like that:

class Homologation < ActiveRecord::Base
  attr_accessible :homologate_by, :homologate_course, :student_id
  belongs_to :user
end

this is the form Im having problems with:

<%= form_for(@homologation) do |f| %>
      <%= render 'shared/error_messages', object: @homologation %>
      <%= f.label :homologate_course %>
      <%= f.collection_select :homologate_course, Course.find(:all), :id, :name, :prompt => "Select a Course" %>

      <%= f.label :homologate_by %>
      <%= f.collection_select :homologate_by, Similar.find(:all), :similar_id, :name, :prompt => "Select a Similar Course" %>
    <div class="form-actions">
      <%= f.submit "Create Homologation", class: "btn btn-large btn-primary" %>
    </div>
    <% end %>
  </div>

Im getting the following error

http://dpaste.com/hold/827744/

the Bartolleti thing is the name of the course I want to be able to show, and that of course is not a method, but I dont know Why Im getting the error, I want to be able to show the names of the similar courses given the first collection field course…

Thank you for your help!

  • 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-14T05:24:52+00:00Added an answer on June 14, 2026 at 5:24 am

    From the doc of collection_select :

    collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {})

    Then with your code you have Course.find(Similar.find_by_id(:similar_id)).name as the text_method, that is why you get this error message.

    One solution could be to add a method on your Similar model to get the similar course name :

    def similar_name
      similar.name
    end
    

    then you can use it as the text_method in your collection_select :

    <%= f.collection_select :homologate_by, Similar.find(:all), :similar_id, :similar_name, :prompt => "Select a Similar Course" %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using MVC3, EF Model first. I have a form with two DropDownList
I have two form fields on my view page, a date input (with a
I have a form with two input text fields: <input id=ModelName_test_0 name=ModelName[test][0] type=text> <input
I have a form with two combo boxes and couple of buttons. One of
I have a form with two text boxes, one select drop down and one
I have a form that has two buttons on it, one yes, one no,
I have a relatively simple problem. I have a model named Item which I've
In .NET4 MVC 4 using Code First I have two classes that form a
I have two PHP model classes named Category and Item. A Category may have
I have an InfoPath form which has two data connections: Connection to a SharePoint

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.