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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:25:53+00:00 2026-06-12T10:25:53+00:00

I’m having a problem when trying to save a new entry into my database.

  • 0

I’m having a problem when trying to save a new entry into my database. On submit, a project should get saved to a project table, and a technology/technologies within that project get saved to a relationship table.

UPDATE Code has been updated after a number of changes

Heres my new action:

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

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


@project_technol = @project.projecttechnols.build





#@project_technol = Projecttechnol.new

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

Create action:

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

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




params[:technol].each_value do |tech|

technology = Technol.find_by_tech(tech.strip)

@project_technol = @project.projecttechnols.build(:technol_id => technology.id)

end


    @project.client = params[:new_client] unless params[:new_client].blank?
    @project.project_owner = params[:new_project_owner] unless params[:new_project_owner].blank?
    @project.tech = params[:new_tech] unless params[:new_tech].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?

    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

And my 3 models:

Project.rb

class Project < ActiveRecord::Base
  attr_accessible  :edited_first_name, :edited_last_name, :first_name, :last_name, :business_div, :client, :customer_benifits, :edited_date, :end_date, :entry_date,  :financials, :industry, :keywords, :lessons_learned, :project_name, :project_owner, :role, :start_date, :status, :summary, :tech , :technols

validates_presence_of :business_div, :client, :customer_benifits, :end_date,  :financials, :industry, :keywords, :lessons_learned, :project_name, :project_owner, :role, :start_date, :status, :summary




has_many :projecttechnols
has_many :technols, :through => :projecttechnols


def self.like(text); "%#{text}%"; end

  def self.search(search_client, search_industry, search_role, search_techs_ids, search_business_div, search_project_owner,  search_status, search_start_date_dd, search_start_date_A, search_start_date_B,  search_keywords)
    # start with a scoped query, to apply more scopes on it afterwards
    _projects = Project.scoped 
    # then, for each of the parameters, apply the scope only if present
    if search_client.present?
      _projects = _projects.where ['client LIKE ?', like(search_client)] 
    end
    if search_industry.present?
      _projects = _projects.where ['industry LIKE ?', like(search_industry)]
    end
    if search_role.present?
      _projects = _projects.where ['role LIKE ?', like(search_role)]
    end

#_projects = _projects.joins(:technols).
 #             where("technols.id" => search_techs_ids)



#_projects = _projects.joins(:projecttechnols).where("projecttechnols.id" => search_techs_ids)


if search_techs_ids.present?
_projects = _projects.joins(:technols).where("technols.id" => search_techs_ids)
end



    if search_business_div.present?
      _projects = _projects.where ['business_div LIKE ?', like(search_business_div)]
    end
    if search_project_owner.present?
      _projects = _projects.where ['project_owner LIKE ?', like(search_project_owner)]
    end

     if search_status.present?
      _projects = _projects.where ['status LIKE ?', like(search_status)]
    end



todays_date = DateTime.now.to_date

if !search_start_date_A.blank? or !search_start_date_B.blank?
    search_start_date_A = Date.parse(search_start_date_A).strftime("%Y-%m-%d")
    search_start_date_B = Date.parse(search_start_date_B).strftime("%Y-%m-%d")
    todays_date = nil
    search_start_date_dd = nil

    end

if search_start_date_dd.blank?
    todays_date = nil
end


if search_start_date_A.present? or search_start_date_B.present?

      _projects = _projects.where [' DATE(start_date) BETWEEN ? AND ?', search_start_date_A, search_start_date_B]
    end


                if search_start_date_dd.present?
      _projects = _projects.where ['DATE(start_date) BETWEEN ? AND ?', search_start_date_dd, todays_date]
    end




    if search_keywords.present?
      _projects = _projects.where ['keywords LIKE ?', like(search_keywords)]
    end
    # now you have applied only the present scopes. return the result, and watch 
    # the query as it executes.
    _projects
  end


def self.paginated_for_index(projects_per_page, current_page)
    paginate(:per_page => projects_per_page, :page => current_page)
  end

end

technol.rb

class Technol < ActiveRecord::Base
  attr_accessible :tech

has_many :projecttechnols
has_many :projects, :through => :projecttechnols
end

projecttechnol.rb

class Projecttechnol < ActiveRecord::Base
  attr_accessible :project_id, :technol_id

belongs_to :technol
belongs_to :project
end

and here is part of the new view, which I think is causing the problem:

<div class="tech">

<% common_techs = [['Mainframe'],['UNIX'],['Windows Servers'],['Networking'],['CISCO'], ['Win7'], ['Telephony'], ['Web services'], ['Website'], ['Cloud'], ['Virtualisation'], ['Data Centre']] %>
 <% db_techs = Technol.all.map {|p| [p.tech]}.uniq %>

<% all_tech = common_techs + db_techs %>


<%= form_for(@technol) do |tech| %>
<div class="field">
    <%= tech.label :tech %><br />
    <%= tech.text_field :tech %>
  </div>
<%end%>

When I click the submit button to create a new project, I get this error:

    RuntimeError in ProjectsController#create

Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id

app/controllers/projects_controller.rb:116:in `block in create'
app/controllers/projects_controller.rb:112:in `each_value'
app/controllers/projects_controller.rb:112:in `create'

These are my params:

    {"utf8"=>"✓",
 "authenticity_token"=>"sPyJbgBKTxa9iHWF9r0Gg/0R/v0l0/e8KwXpPebzdus=",
 "project"=>{"project_name"=>"",
 "status"=>"Active",
 "client"=>"",
 "business_div"=>"",
 "project_owner"=>"",
 "start_date"=>"01-10-2012",
 "entry_date"=>"2012-10-03",
 "end_date"=>"09-10-2012",
 "role"=>"",
 "industry"=>"",
 "summary"=>"",
 "lessons_learned"=>"",
 "customer_benifits"=>"",
 "financials"=>"",
 "keywords"=>""},
 "new_client"=>"",
 "new_business_div"=>"",
 "new_project_owner"=>"",
 "technol"=>{"tech"=>"TESTER"},
 "new_role"=>"",
 "new_industry"=>"",
 "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-12T10:25:54+00:00Added an answer on June 12, 2026 at 10:25 am

    This is because you’re looking up for value of key “id” in the hash returned by params[:technols]. However when you look at that hash {"tech"=>"Web services"} there is only one key which is “tech”. Hence when you try to do params[:technol][:id] you basically get a nil object.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
I have a reasonable size flat file database of text documents mostly saved in
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into

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.