嘗試在我的CRM項目中創建新作業時出現無方法錯誤。當我在一個月前開始在公司工作時,我參與了這個項目,幾次檢查過代碼庫,沒有看到問題或者事情沒有加在一起。我覺得自己因爲沮喪而忽視了它,所以我正在尋求一些經驗豐富的Rails開發人員的幫助。提前致謝!JobsController中的NoMethodError#new
作業控制器的有關部分發生錯誤:
# GET /jobs/new
def new
@job = Job.opportunity.new do |j|
if params[:opportunity_id].present?
j.opportunity_id = params[:opportunity_id]
end
任務/新視圖:
<% @job[:opportunity_id] = params[:opportunity_id] %>
<% title "New #{@job.opportunity.name} Job"%>
<%
@job[:name] = @job.opportunity.name
@pm = @job.opportunity.pm_id
%>
<br><br>
<%= render 'form' %>
工作模式:
class Job < ActiveRecord::Base
mount_uploader :file1, AttachmentUploader
belongs_to :cost_proposal
belongs_to :opportunity
def Job
has_many :opportunities
end
end
職位表中schema.rb:
create_table 'jobs', force: true do |t|
t.integer 'cost_proposal_id'
t.string 'number'
t.string 'name'
t.date 'flight_date'
t.string 'flight_sub'
t.string 'camera'
t.string 'roll'
t.string 'map_type'
t.integer 'plan_only'
t.integer 'lab_only'
t.integer 'est_hrs_model'
t.date 'due_date'
t.integer 'edge_job_id'
t.integer 'custom_trans'
t.integer 'comp_inhouse'
t.date 'delivered_date'
t.integer 'done'
t.date 'control_in'
t.string 'control_status'
t.date 'at_date'
t.string 'control_results'
t.integer 'control_check'
t.string 'scan_staff'
t.date 'scan_date'
t.integer 'scan_check'
t.string 'comp_staff'
t.date 'comp_date'
t.integer 'comp_check'
t.string 'comp_sub'
t.date 'comp_sub_due_date'
t.integer 'comp_sub_rec'
t.string 'img_staff'
t.date 'img_date'
t.integer 'img_check'
t.string 'edit_staff'
t.date 'edit_date'
t.integer 'edit_check'
t.text 'notes'
t.string 'file1'
t.string 'file2'
t.string 'file3'
t.string 'file4'
t.string 'file5'
t.string 'add_files'
t.datetime 'created_at'
t.datetime 'updated_at'
t.integer 'flown'
t.integer 'cust_trans'
t.integer 'delivered'
t.string 'at_staff'
t.integer 'at_check'
t.integer 'opportunity_id'
end
什麼是錯誤,在什麼情況下發生? – PoloniculMov
@PoloniculMov job = Job.opportunity.new do | j |是發生錯誤的地方。 – kmaune