Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 3.2 - Recieving a weird error when trying to edit a new database entry
    primarykey
    data
    text
    <p>I have an object called <code>Job</code> that belong to another object called <code>client</code> in a many relationship. </p> <p>Here's my job model</p> <pre><code>class Job &lt; ActiveRecord::Base belongs_to :client end </code></pre> <p>Here's my Client model</p> <pre><code>class Client &lt; ActiveRecord::Base has_many :jobs end </code></pre> <p>For a new job, I simply want to assign it during creation to a client.</p> <p>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.</p> <p>When I try to edit the job and save it again im recieving the following error.</p> <pre><code>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' </code></pre> <p>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.</p> <p>Here's my controller.</p> <p>class JobsController &lt; ApplicationController</p> <pre><code> 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 </code></pre> <p>Any pointers or a nod in the right direction would be appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload