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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:11:50+00:00 2026-06-14T22:11:50+00:00

I have an app where a user can enter a project into a database.

  • 0

I have an app where a user can enter a project into a database.

There is an option where they can select a number of different technologies for their project. At the moment, the app flags up an error if the user doesn’t select at least 1 technology.

I am wanting to change this so that if they don’t select a technology, it automatically goes down as “other” instead.

Here is my project controller actions, new and create:

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

        @all_technols = Technol.order('tech ASC') 
        @all_technols = Technol.all
        tech_ids = params[:technols][:id].reject(&:blank?) unless params[:technols].nil?


        @project_technol = @project.projecttechnols.build

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



def create  
    @project = Project.new(params[:project])
        @project.client = params[:new_client] unless params[:new_client].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

Here is the new view for the technology field

<ul> 


<% @all_technols.each do |technol| %> 



<li class="split"> 
<%= check_box_tag "project[technol_ids][]", technol.id,  @project.technols.include?(technol) %> 
<%= technol.tech %> 
</li> 

<% end %>
</ul> 

The technology ID for “other” in the technols table is “18”. So is there a way to say that if no technology is chosen, then :technol_id => ["18"].

I was given help earlier, and it was suggested that I should add this:

def create
  ...
  technol_ids = params[:technol_ids].blank? ? [18] : params[:technol_ids]
  technol_ids.each do |id|
  ...
  end
  ...
end

I am having trouble getting this to work. I don’t think I am putting it in the right bit of my code. I’m still new to rails, so please remember this when trying to help. Thanks very much

EDIT

With no technols_id selected

Processing by ProjectsController#create as HTML
  Parameters: {"utf8"=>"Ô£ô", "authenticity_token"=>"8Hgc1GXqNhWkzO3Wgkfpf6z+fdImf6QvAv0XLbP0a5g=", "project"=>{"project
_name"=>"Test", "archive"=>"0", "username"=>"test", "status"=>"Active", "exception_pm"=>"", "client"=>"", "business_d
iv"=>"", "project_owner"=>"", "start_date"=>"11-12-2012", "first_name"=>"test", "last_name"=>"test", "fullname"=>
"test test", "entry_date"=>"2012-11-26", "end_date"=>"19-12-2012", "techinfo"=>"Test", "role"=>"", "industry"=>""
, "summary"=>"Test", "lessons_learned"=>"Test", "customer_benefits"=>"Test", "financials"=>"£500,000 - £999,999 "}, "n
ew_exception_pm"=>"Test", "new_client"=>"Test", "new_business_div"=>"Test", "new_project_owner"=>"Test", "new_role"=>"Te
st", "new_industry"=>"Test", "commit"=>"Save New Project"}

With 1 technols_id

Started POST "/projects" for 192.168.16.127 at 2012-11-26 16:47:27 +0000
Processing by ProjectsController#create as HTML
  Parameters: {"utf8"=>"Ô£ô", "authenticity_token"=>"8Hgc1GXqNhWkzO3Wgkfpf6z+fdImf6QvAv0XLbP0a5g=", "project"=>{"project
_name"=>"Test", "archive"=>"0", "username"=>"Test", "status"=>"Active", "exception_pm"=>"", "client"=>"", "business_d
iv"=>"", "project_owner"=>"", "start_date"=>"11-12-2012", "first_name"=>"Test", "last_name"=>"McLaughlin", "fullname"=>
"Test Test", "entry_date"=>"2012-11-26", "end_date"=>"20-12-2012", "technol_ids"=>["1"], "techinfo"=>"Test", "rol
e"=>"", "industry"=>"", "summary"=>"Test", "lessons_learned"=>"Test", "customer_benefits"=>"Test", "financials"=>"£250,
000 - £499,999 "}, "new_exception_pm"=>"Test", "new_client"=>"Test", "new_business_div"=>"Test", "new_project_owner"=>"
Test", "new_role"=>"Test", "new_industry"=>"Test", "commit"=>"Save New Project"}
  • 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-14T22:11:51+00:00Added an answer on June 14, 2026 at 10:11 pm

    First of all, the name of the field should be used to get the parameters, use like my example.
    You are receiving an array of tech ids, right? So instead of using if to check nil, use this:

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

    It will turn this parameter into array if it is nil.

    params[:project][:technol_ids].each do |tech_id|
       @project_technol = @project.projecttechnols.build(:technol_id => tech)
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app where a user can enter a project into a database.
I have an app where a user can enter projects into a database. One
I have an app that allows users to enter a project into a database.
I have a textfield in my app, whre the user can enter any number
I have created edittexts in which user can enter numbers. In my app user
I am trying to allow a user to enter a project into a database.
In my iPhone app I have a settings page where a user can enter
I have an app where the user can create a new project and search
I have an android app, in which user can enter any xml source url
I have a small app, where user can make some calculations and solve equations.

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.