title: Rails 4 NoMethodError in Jobs#new
body: <p>A little background, I took over a project that someone else started and hasn't worked on for 8ish months. The project is a CRM application built using Rails 4. I'm having a little trouble picking up where they left off, and am looking for help from seasoned Rails developers. The error I am receiving is when I try to add a new job from a job tracker page. The error I am receiving is:</p>
  
  <pre><code>ActionView::Template::Error (undefined method `opportunity' for #&lt;Job:0x62d0240&gt;):
      1: &lt;% @job[:opportunity_id] = params[:opportunity_id] %&gt;
      2: &lt;% title "New #{@job.opportunity.name} Job"%&gt;
      3:
      4: &lt;%
      5: @job[:name] = @job.opportunity.name
    app/views/jobs/new.html.erb:2:in `_app_views_jobs_new_html_erb___882142983_51776136'
  </code></pre>
  
  <p>and the error is occuring on line 2 of the above. I will post relevant code, let me know if I need to add anything else. Thanks in advance!</p>
  
  <p><strong>Jobs new view (where error is occuring)</strong></p>
  
  <pre><code>&lt;% @job[:opportunity_id] = params[:opportunity_id] %&gt;
  &lt;% title "New #{@job.opportunity.name} Job"%&gt;
  
  &lt;%
  @job[:name] = @job.opportunity.name
  @pm = @job.opportunity.pm_id
  
  
  %&gt;
  
  &lt;br&gt;&lt;br&gt;
  &lt;%= render 'form' %&gt;
  </code></pre>
  
  <p><strong>Opportunity Controller</strong></p>
  
  <pre><code>class OpportunitiesController &lt; ApplicationController
    before_action :set_opportunity, only: [:show, :edit, :update, :destroy]
    load_and_authorize_resource
    # GET /opportunities
    # GET /opportunities.json
    def index
      @opportunities = Opportunity.all
    end
  
    # GET /opportunities/1
    # GET /opportunities/1.json
    def show
    end
  
    # GET /opportunities/new
    def new
      @opportunity = Opportunity.new
    end
  
    # GET /opportunities/1/edit
    def edit
    end
  
    # POST /opportunities
    # POST /opportunities.json
    def create
      @opportunity = Opportunity.new(opportunity_params)
  
      respond_to do |format|
        if @opportunity.save
          format.html { redirect_to @opportunity, notice: 'Opportunity was successfully created.' }
          format.json { render :show, status: :created, location: @opportunity }
        else
          format.html { render :new }
          format.json { render json: @opportunity.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # PATCH/PUT /opportunities/1
    # PATCH/PUT /opportunities/1.json
    def update
      respond_to do |format|
        if @opportunity.update(opportunity_params)
          format.html { redirect_to @opportunity, notice: 'Opportunity was successfully updated.' }
          format.json { render :show, status: :ok, location: @opportunity }
        else
          format.html { render :edit }
          format.json { render json: @opportunity.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # DELETE /opportunities/1
    # DELETE /opportunities/1.json
    def destroy
      @opportunity.destroy
      respond_to do |format|
        format.html { redirect_to opportunities_url, notice: 'Opportunity was successfully destroyed.' }
        format.json { head :no_content }
      end
    end
  
    private
      # Use callbacks to share common setup or constraints between actions.
      def set_opportunity
        @opportunity = Opportunity.find(params[:id])
        @film_specs = @opportunity.film_specs.all
        @digital_specs = @opportunity.digital_specs.all
      end
  
      # Never trust parameters from the scary internet, only allow the white list through.
      def opportunity_params
        params.require(:opportunity).permit(:employee_id, :emp2_id, :emp3_id, :name, :prop_date, :opp_status_id, :delay, :won, :lost, :con_signed, :quote_won_id, :total_cost, :exp_close, :pri_comp_id, :notes, :location, :pm_id)
      end
  end
  </code></pre>
  
  <p><strong>Job Controller</strong></p>
  
  <pre><code>class JobsController &lt; ApplicationController
    before_action :set_job, only: [:show, :edit, :update, :destroy]
    skip_load_and_authorize_resource
    # GET /jobs
    # GET /jobs.json
    def index
      @jobs = Job.all
    end
  
    # GET /jobs/1
    # GET /jobs/1.json
    def show
    end
  
    # GET /jobs/new
    def new
      @job = Job.new do |j|
        if params[:opportunity_id].present?
          j.opportunity_id = params[:opportunity_id]
        end
      end
    end
  
    # GET /jobs/1/edit
    def edit
    end
  
    # POST /jobs
    # POST /jobs.json
    def create
      @job = Job.new(job_params)
  
      respond_to do |format|
        if @job.save
          format.html { redirect_to @job, notice: 'Job was successfully created.' }
          format.json { render :show, status: :created, location: @job }
        else
          format.html { render :new }
          format.json { render json: @job.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # PATCH/PUT /jobs/1
    # PATCH/PUT /jobs/1.json
    def update
      respond_to do |format|
        if @job.update(job_params)
          format.html { redirect_to @job, notice: 'Job was successfully updated.' }
          format.json { render :show, status: :ok, location: @job }
        else
          format.html { render :edit }
          format.json { render json: @job.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # DELETE /jobs/1
    # DELETE /jobs/1.json
    def destroy
      @job.destroy
      respond_to do |format|
        format.html { redirect_to jobs_url, notice: 'Job was successfully deleted.' }
        format.json { head :no_content }
      end
    end
  
    private
      # Use callbacks to share common setup or constraints between actions.
      def set_job
        @job = Job.find(params[:id])
      end
  
      # Never trust parameters from the scary internet, only allow the white list through.
      def job_params
        params.require(:job).permit(:opportunity_id, :number, :name, :flight_date, :flight_sub, :camera, :roll, :map_type, :plan_only, :lab_only, :est_hrs_model, :due_date, :edge_job_id, :custom_trans, :comp_inhouse, :delivered_date, :done, :control_in, :control_status, :at_date, :control_results, :control_check, :scan_staff, :scan_date, :scan_check, :comp_staff, :comp_date, :comp_check, :comp_sub, :comp_sub_due_date, :comp_sub_rec, :img_staff, :img_date, :img_check, :edit_staff, :edit_date, :edit_check, :notes, :file1, :file2, :file3, :file4, :file5, :add_files)
      end
  end
  </code></pre>
  
  <p><strong>Opportunity Model</strong></p>
  
  <pre><code>class Opportunity &lt; ActiveRecord::Base
    belongs_to :employee
    has_one :user
    has_many :film_specs
    has_many :digital_specs
    has_many :film_quotes
    has_many :cost_proposals
    has_many :jobs
  
    validates_presence_of :opp_status_id
  end
  </code></pre>
  
  <p><strong>Job Model</strong></p>
  
  <pre><code>class Job &lt; ActiveRecord::Base
    mount_uploader :file1, AttachmentUploader
    belongs_to :cost_proposal
    has_many :opportunities
  end
  </code></pre>
  
  <p><strong>Job Schema</strong></p>
  
  <pre><code>  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
  </code></pre>
  
  <p><strong>Opportunity Schema</strong></p>
  
  <pre><code>  create_table "opportunities", force: true do |t|
      t.integer  "employee_id"
      t.integer  "emp2_id"
      t.integer  "emp3_id"
      t.string   "name"
      t.datetime "prop_date"
      t.integer  "opp_status_id"
      t.string   "delay"
      t.date     "con_signed"
      t.integer  "quote_won_id"
      t.float    "total_cost"
      t.date     "exp_close"
      t.integer  "pri_comp_id"
      t.text     "notes"
      t.datetime "created_at"
      t.datetime "updated_at"
      t.string   "lost"
      t.string   "won"
      t.string   "location"
      t.integer  "pm_id"
      t.integer  "job_id"
    end
  </code></pre>