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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:24:18+00:00 2026-05-26T12:24:18+00:00

In a rails project I have two entities, Users and Institutions, they have a

  • 0

In a rails project I have two entities, Users and Institutions, they have a many-to-many relationship.

The views for them are set up to create new users and institutions but I want to have another view for linking the two.
In rails console all I have to do is

myuser.institutions << the_institution_i_just_created

The controller can do some of the work but how do I handle the submissions and the forms? I want to use a selection box so that the input is limited to the Institutions already in existence.

<select id="institution_selection" name="institution_sel">
<% selections = []
   Institution.all.each do |institution|
      pair = [institution.name, institution.id]
      selections.concat([pair])
   end 
   %>
   <%= options_for_select(selections) %>
</select>

So the question in summary is how do I map this submission to an object so that in the controller I can do add it to the relation?

The solution was:

Alright, so this is the solution I came up with, I’m sure there is a better way to go about it and I’ll continue to look into it but at least I got something close to what I was aiming for

def test
  if !session[:user]
     redirect_to users_path, notice: "Please login first"
  end
  if params[:institution]
     @user = User.find(session[:user])
     @institution = Institution.find(params[:institution][:id])
     @user.institutions << @institution
     redirect_to @user, notice: "Institution was successfully added "
  end
end

and for the view

<%= form_tag("/users/test", :method => "post") do %>
<%= collection_select :institution, :id, Institution.all, :id, :name %>
<%= submit_tag("Search") %>
<% 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-26T12:24:18+00:00Added an answer on May 26, 2026 at 12:24 pm

    Use collection_select

    <% from for @instancevar do |form| %>
         <%= form.collection_select :institution_id, Institution.all, :id, :name %> 
         # Do other stuff....
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two entities, projects and users. These are modeled in Rails using Mongoid
Starting a new rails project and we have a well-thought-out color palette, and want
I have a rails project that I would like to set up email notifications
I'm using MetaSearch gem in my Rails 3 project. I have two models: class
I'm brand new to Rails. I have one Rails project on my machine, but
I have two tables in my rails application Categories and Projects. The relationship between
I'm joined a rails project which have been going for past two months. I
So I just started my first rails project yesterday. I had two many-to-many (has_and_belongs_to_many)
I am developing a project with rails 3.1.3 and kaminari 0.13.0. I have two
In my project rails have a CRUD for Users, when i am in the

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.