jeudi 25 août 2016

ActionView::Template::Error (undefined method `full_name' for nil:NilClass )

I am adding new role in my role table, role is successfully added and it's working properly. In the view automatically hr folder created (I add two new page _internal_employee_page.html.erb, _employee_details.html.erb) I have created one controller hr_controller.rb

My _internal_employee_page.html.erb page

<div class="client-dash-page head-border matching-profile recrut-dashboard">
    <div id="job_details">
        <%= render "hr/employee_details" %>
    </div>
</div>

My _employee_details.html.erb page

<div class="panel-group" id="client-dash-accordion" role="tablist" aria-multiselectable="true">

Employee Name : <%= @employees.full_name %>


This is my Controller

class HrController < ApplicationController

def internal_employee_page
    @employees = OfferLetter.all        
end

def employee_details
    @employees = OfferLetter.all
end

end

I have two model ( UserHr.rb and OfferLetter.rb ) this is my UserHr.rb model

class UserHr < User
attr_accessor :full_name
has_many :offer_letter

end

My OfferLetter.rb model

class OfferLetter < ActiveRecord::Base
    belongs_to :user_hr
end

This is my routes.rb

Recruitment::Application.routes.draw do

get 'hr/internal_employee_page' => 'hr#internal_employee_page', as: :internal_employee_page end

The error is here

Employee Name : <%= @employees.full_name %>

full_name is column name, I want to print the value of full_name column. Please help me I have try so many times but i am not solve this problems.

Aucun commentaire:

Enregistrer un commentaire