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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:31:40+00:00 2026-06-03T10:31:40+00:00

I have an object called Job that belong to another object called client in

  • 0

I have an object called Job that belong to another object
called client in a many relationship.

Here’s my job model

class Job < ActiveRecord::Base
  belongs_to :client
end

Here’s my Client model

class Client < ActiveRecord::Base 
  has_many :jobs
end

For a new job, I simply want to assign it during creation to a client.

When I try to create a new job however. All im seeing in my view is the id of the job instead of the name and the internals of the created model are also empty.

When I try to edit the job and save it again im recieving the following error.

Client(#2157214400) expected, got String(#2151988620)

Application Trace | Framework Trace | Full Trace
app/controllers/jobs_controller.rb:61:in `block in update'
app/controllers/jobs_controller.rb:60:in `update'

I guess this could be because my controller is wrong in some way but this is my first app so im not quite sure where to look.

Here’s my controller.

class JobsController < ApplicationController

    def index
      @job = Job.all

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

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

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

    def new
      @job = Job.new(params[:id])

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

    def edit
      @job = Job.find(params[:id])
    end

    def create
      @job = Job.new(params[:jobs])

      respond_to do |format|
        if @job.save
          format.html { redirect_to @job, notice: 'job was successfully created.' }
          format.json { render json: @job, status: :created, location: @job }
        else
          format.html { render action: "new" }
          format.json { render json: @job.errors, status: :unprocessable_entity }
        end
      end
    end

    def update
      @job = Job.find(params[:id])

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

    def destroy
      @job = Job.find(params[:id])
      @job.destroy

      respond_to do |format|
        format.html { redirect_to :jobs }
        format.json { head :no_content }
      end
    end
  end

Any pointers or a nod in the right direction would be 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-03T10:31:42+00:00Added an answer on June 3, 2026 at 10:31 am

    The problem is because Activerecord expected an instance of Client object , and it has method client= (because belogs_to association)
    When you bind AR object from request you should use client_id parameter instead of client

    you can read about http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-belongs_to

    if client count is short you can use select with client_id as name
    Example http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html

    so you can do something like that

    select("job", "client_id", Client.all.collect {|c| [ c.name, c.id ] }, {:include_blank => 'None'})
    

    instead of

     f.text_field :client, :class => 'text_field' 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the scenario: I have an object called a Transaction that needs to
I have a data object -- a custom class called Notification -- that exposes
I have an object called human and that object has a field called job.
I have a job object for long running operations that works like this: Class
I have an object called users that I use to store user objects that
I have an object called Contact. A Contact has a relationship with a set
I have an object class called BOM. It has a method, getChildItem() which returns
I have a parent object called Page that has a List of objects called
I have a UITableView that displays various nsstrings from a custom object called a
I have a class that inherits from CCSprite called GameObject . I also have

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.