我有一個對象叫做Job
,它屬於另一個對象 ,這個對象被稱爲client
,有許多關係。Rails 3.2 - 嘗試編輯新的數據庫條目時收到一個奇怪的錯誤
這是我的工作模式
class Job < ActiveRecord::Base
belongs_to :client
end
這裏是我的客戶模型
class Client < ActiveRecord::Base
has_many :jobs
end
一份新的工作,我只是想創建一個客戶端過程中分配它。
但是,當我嘗試創建新工作時。在我看來,所有即時消息都是作業的ID而不是名稱,創建的模型的內部也是空的。
當我嘗試編輯作業並再次保存時,我收到以下錯誤。
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'
我想這可能是因爲我的控制器是錯誤的在某些方面,但是這是我的第一個應用程序,所以我不是很確定在哪裏看。
這是我的控制器。
類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
任何指針或在正確的方向上的點頭,將不勝感激。
顯示目前美國對編輯工作的形式。 – jdoe
窗體很長,但在這裏發佈.. https://gist.github.com/2638538 – Keva161