2016-08-24 12 views
0

CRM 프로젝트에서 새 작업을 만들 때 오류가 발생하지 않습니다. 한 달 전에 회사에서 시작했을 때이 프로젝트를 끝내고 코드베이스를 몇 번 검토 한 후 문제가 보이지 않거나 모든 것이 합쳐지지 않는 곳을 보았습니다. 나는 좌절감 때문에 그것을 간과하는 것처럼 느껴져서 숙련 된 레일 개발자로부터 도움을 요청합니다. 미리 감사드립니다!NoMethodError in JobsController # 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에서3210

작업 테이블 :

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 
+1

어떤 오류가 발생합니까? – PoloniculMov

+0

@PoloniculMov job = Job.opportunity.new do | j | 오류가 발생한 곳입니다. – kmaune

답변

1

귀하 협회는 몇 가지주의가 필요합니다. 귀하의 직무 모델에는 기회와 기회가 모두 있습니다. 이것이 어떻게 작동해야하는지가 아닙니다. 기회 수집에 있지만 속성이 설정된 primary_opportunity를 가질 수 있습니다. 모든

첫째, 이것은 잘못된 것입니다 :

def Job 
    has_many :opportunities 
    end 

는 작업 (자본 J)라는 방법이 안, 대문자로 시작하는 단어는 클래스와 상수가 아닌 방법이 있습니다. 클래스 메소드 (def job)에는 인스턴스 범위가 없습니다. 이것은 협회를위한 장소가 아닙니다. 인스턴스화 전에 액세스 할 수있는 메서드를 만들려면 def Job 안에 메서드를 넣습니다. 연관은 인스턴스 메소드 정의 내부에 있어야합니다 (def Job 제외) def 작업을 제거하고 종료하십시오. 당신이 belongs_to :opportunity 또는 has_many :opportunities 관계를 갖고 싶어 결정해야합니다, 거기에서

class Job < ActiveRecord::Base 
    mount_uploader :file1, AttachmentUploader 
    belongs_to :cost_proposal 
    belongs_to :opportunity 
    has_many :opportunities 
end 

: 이것은 당신에게 모델을 제공 할 것입니다. 각 작업에 여러 작업이있는 경우 belongs_to을 제거하십시오.

두 번째로, @job = Job.opportunity.new do |j| 행은 인스턴스가 아닌 상수에서 메소드를 호출합니다. 위의 코드는 당신이 당신의 중복 협회의 has_many 변형을 사용하는 가정입니다

@job = Job.new 
@job.opportunties.new do |j| 

:이 라인을 변경합니다.

희망이 있습니다.

+0

감사합니다. 나는 이것을 줄 것이다. 이것은 내가 작성하지 않은 모든 코드이므로,이 코드를 모두 정리하고 올바르게 작동시켜야합니다. 다시 한 번 고마워, 고마워. – kmaune

+0

프로젝트에서 연관성에 대한 관심이 필요하다는 것을 깨달았습니다. 다시 한번 감사드립니다. – kmaune