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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:06:01+00:00 2026-06-04T00:06:01+00:00

I have two models jobs and clients . A user can simple create a

  • 0

I have two models jobs and clients.

A user can simple create a client and then assign them a number of jobs.

Here’s my models for both.

job.rb

class Job < ActiveRecord::Base
  has_and_belongs_to_many :clients
end

client.rb

class Client < ActiveRecord::Base 
  has_and_belongs_to_many :jobs
end

My form for creating a new job looks like this:

<%= simple_form_for :job do |f| %>
  <%= f.input :name %>
  <%= <%= collection_select(:job, :client_ids, Client.all, :id, :name, {:include_blank => 'None'}, { :multiple => true }) %>%>
  <%= f.button :submit %>
<% end %>

So as you can see there is a drop down box on the form which contains all of the clients.

When try to save it however, I recieve this messed:

ActiveRecord::UnknownAttributeError in JobsController#create

unknown attribute: client_id

Application Trace | Framework Trace | Full Trace
app/controllers/jobs_controller.rb:22:in `new'
app/controllers/jobs_controller.rb:22:in `create'
Request

Parameters:

{"utf8"=>"✓",
 "authenticity_token"=>"0ZVYpM9vTgY+BI55Y9yJDwCJwrwSgGL9xjHq8dz5OBE=",
 "job"=>{"name"=>"Sample Monthly",
 "client_id"=>"1"},
 "commit"=>"Save Job"}

My job controller is quite basic and looks like this:

class JobsController < ApplicationController

  def index
    @jobs = Job.find(:all)

    respond_to do |format|
      format.html # index.html.erb
      format.xml { render :xml => @job }
    end
  end

  def new
    @jobs = Job.new 

    respond_to do |format|
      format.html # index.html.erb
      format.xml { render :xml => @job }
    end
  end

  def create
    @jobs = Job.new(params[:job])
    respond_to do |format|
      if @jobs.save
        format.html { redirect_to @jobs, notice: 'Job was successfully created.' }
        format.json { render json: @jobs, status: :created, location: @jobs }
      else
        format.html { render action: "new" }
        format.json { render json: @jobs.errors, status: :unprocessable_entity }
      end
    end
  end

  def show
    @jobs = Job.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @jobs }
    end
  end
end

I have a junction table setup with both job_id and client_id as a integer value in them.
So I think its just a case of defining them in my controller under the new and create action like the error message suggests.

This is my first Rails app though sand im not quite sure how.

Any help would be greatly appreciated!

  • 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-04T00:06:03+00:00Added an answer on June 4, 2026 at 12:06 am

    Problem might be in your form. Try to replace this

    <%= <%= collection_select(:job, :client_ids, Client.all, :id, :name, {:include_blank => 'None'}, { :multiple => true }) %>%>
    

    with

    <%= f.association :clients %>
    

    so the form will look like this

    <%= simple_form_for @job do |f| %>
      <%= f.input :name %>
      <%= f.association :clients %>
      <%= f.button :submit %>  
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey, need a little help here. I have two models: class User < ActiveRecord::Base
i have two models: class Category has many :jobs end class Job belongs_to :category
I have two models, user and group. I also have a joining table groups_users.
I have two models, Image and Tag . Each Image object can have more
I have two models: class User end class Message belongs_to :sender, :class_name=> 'User' belongs_to
I have two models: Person and Address which I'd like to create in a
I have two models -- User and Entry -- that are related through a
I have two models, user & offline_user, and I want to use a dropdown
I have two models pages and author, here is the code of model pages:
I have two models Jobs and Questions. A job has many questions and questions

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.