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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:28:09+00:00 2026-06-05T12:28:09+00:00

I am trying to create a form that allows to assign multiple projectmembers to

  • 0

I am trying to create a form that allows to assign multiple projectmembers to a project.
(User and Project model being related through UserProject )

here is my view:

<div class="field">
<%= fields_for :projectmember do |u| %> 
  <%= u.label :projectmember %><br />
  <%= select_tag :projectmember, options_for_select(User.all.collect {|u| [u.id, u.lastname]}, :projectmember),:multiple => true, :prompt => 'Select Person' %>

<% end %>
  </div>

i have put the projectmember tag all over the place but i can’t figure it out how to save this field projectmember into my db projects and user_projects !!??

my projects_controller :

def new
@project = Project.new
@user_project=UserProject.new
@user=User.all    
@user_lastnames = User.all.collect do |u| 
  u.lastname
end

respond_to do |format|
  format.html # new.html.erb
  format.json { render json: @project }
end
end

and

def create
@project = Project.new(params[:project])  

respond_to do |format|
  if @project.save
    format.html { redirect_to @project, notice: 'Project was successfully created.' }
    format.json { render json: @project, status: :created, location: @project }         

    @user_project=UserProject.create(:project_id => @project.id, :user_id => @project.projectmember)       

  else
    format.html { render action: "new" }
    format.json { render json: @project.errors, status: :unprocessable_entity }
  end
end
end

After creating one instance, the command using the console : @project=Project.all gives :
Project id: 55, projectname: “fdfd”, projectdescription: “fdfd”, projectheader: “5”, projectmember: nil, projecttypename: “dffd”>]

  • 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-05T12:28:11+00:00Added an answer on June 5, 2026 at 12:28 pm

    Assuming your associations are something like this:

    class Project < ActiveRecord::Base
      has_many :project_users
      has_many :users, :through=>:project_users
    end
    

    …for your project form, use the following helper with the “name” option (:name=>’project[user_ids][]’) to pass the selected ids to your controller:

    <%= select_tag :user_ids, options_for_select(User.all.collect {|u| [u.lastname, u.id]}),:multiple => true, :prompt => 'Select Person', :name=>'project[user_ids][]' %>
    

    That will give you the selected ids in the params and then you’ll have to hook up your controller actions to assign them. For example:

    def create
        @project = Project.new(params[:project])  
        users = User.find(params[:project][:user_ids]) rescue []
        @project.users = users
        if @project.save
          ...
        else
          ...
        end
    end
    
    def update
        @project = Project.find(params[:id])
        users = User.find(params[:project][:user_ids]) rescue []
        @project.users = users
        if @project.update_attributes(params[:project])
          ...
        else
         ...
        end
    end
    

    In order to get the selected items to re-select when you render the edit form, I’m assuming you’d have to add that as an argument to the options_for_select method. Not exactly sure about that. An alternative to doing all of the above would be to use checkboxes to select the users since the checked could be set for each assigned user when the form renders. Good luck.

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

Sidebar

Related Questions

I am trying to create an asp.net web form that allows a user to
I am trying to create an upload form that allows the user to select
I am trying to create a user form that will allow the user to
I'm trying to create a child form that helps the user to enter data
I'm building an application that allows the user to create a Human model (graphical
I am trying to create a button on my access form that allows for
I am trying to create an email form that allows you to send an
Basically I am trying to make a simple form that allows the user to
I'm trying to create a C# form app that will allow me to use
I'm trying to create a form that based on the users input would determine

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.