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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:06:34+00:00 2026-06-13T09:06:34+00:00

I have an app that allows a user to enter and edit projects in

  • 0

I have an app that allows a user to enter and edit projects in a table called Projects. One of the fields allows them to check technologies for that project. They are stored in a separate table called Technols, and the relationship between the tables is called Projecttechnols.

As an example, I have a Project X, which has many technologies, tech1, tech2 and tech3. If I go into edit the project, I can remove or add the technolgies to the project, and update the project at will. My problem starts though, when I try to take all the projects out of project. If I try this, nothing is changed, and the technologies stay the same.

I have no problem creating a new project with no technologies, and I can go back into that project and edit by inserting technologies, but if I go back to edit it again with technologies added, and try to remove them all. Nothing happens.

Here are my new, edit, create and update actions from the project controller:

def new
  @project = Project.new
  @technol = Technol.new(params[:tech])

  @all_technols = Technol.all

  @project_technol = @project.projecttechnols.build

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

# GET /projects/1/edit
def edit
  @project = Project.find(params[:id])
  @project_technol = @project.projecttechnols.build

  puts @project.inspect
  puts @project.technols.inspect
end

# POST /projects
# POST /projects.json
def create  
  @project = Project.new(params[:project])
  @project.client = params[:new_client] unless params[:new_client].blank?
  @project.role = params[:new_role] unless params[:new_role].blank?
  @project.industry = params[:new_industry] unless params[:new_industry].blank?
  @project.business_div = params[:new_business_div] unless params[:new_business_div].blank?

  if !params[:technols].nil?
    params[:technols][:id].each do |tech|
      if !tech.empty?
        @project_technol = @project.projecttechnols.build(:technol_id => tech) 
      end
    end
  end

  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 }
    else
      format.html { render action: "new" }
      format.json { render json: @project.errors, status: :unprocessable_entity }
    end
  end
end

# PUT /projects/1
# PUT /projects/1.json
# PUT /projects/1
# PUT /projects/1.json
def update
  @project = Project.find(params[:id])

  puts @project.inspect
  puts @project.technols.inspect

  params['project'][:client] = params[:new_client] unless params[:new_client].blank?
  params['project'][:role] = params[:new_role] unless params[:new_role].blank?
  params['project'][:industry] = params[:new_industry] unless params[:new_industry].blank?
  params['project'][:business_div] = params[:new_business_div] unless params[:new_business_div].blank?              

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

Here is my edit view for the tech bit:

<div class="tech" STYLE="text-align: left;">
  <b>Technologies:</b>
  <style>
    .split { text-align:left; }
  </style>   

  <p>
    <ul>
      <% for technol in Technol.all %> 
        <li class="split"> 
          <%= check_box_tag "project[technol_ids][]", technol.id,  @project.technols.include?(technol) %> 
          <%= technol.tech %> 
        </li>
      <% end %> 
    </ul>
  </p>

I am new to Rails, so it might be something really simple. All help will be appreciated. Thanks in advance.

  • 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-13T09:06:35+00:00Added an answer on June 13, 2026 at 9:06 am

    If the user unchecks all project[technol_ids][] checkboxes, then that field doesn’t appear in params at all. At least one checkbox must be checked to have the field be present. So hopefully you can understand why the model doesn’t change any of the projecttechnol records.

    To fix this, make sure that there is something stored for the param at the top of your update action:

    params[:project][:technol_ids] ||= []
    

    This ensures that you have an empty array if no checkboxes are checked. Passing an empty array into the model should should clear out all records that are present.

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

Sidebar

Related Questions

I have a relatively simple web app, that allows the user to enter two
I have an app that allows the user to choose an image, at design
I have an app that allows the user to choose a picture from their
I have a small tab on an app that allows user to lookup a
basically I have an admin flex page that allows the user to enter text
I have an app that allows the user to take photos using front facing
I have used TimeSpan control in my windows app C# that allows the user
I wrote an app that allows the user to enter data in a UITextField,
I'm writing a web app, with Codeigniter, that allows a user to enter query
We have an Ruby on Rail app that allows the user to save a

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.