I am trying to create a resume builder. Inside the resume, I would like to display the first corresponding Job
title to a specific User
in the show.html.erb
.
I first made sure that Jobs has the user_id foreign key..
Schema
create_table "jobs", force: true do |t|
t.string "title"
t.string "company"
t.date "date_start"
t.date "date_end"
t.boolean "current"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "user_id"
t.integer "career_id"
end
..and the relationships are like so:
User Model
class User < ActiveRecord::Base
has_one :career
has_many :jobs, through: :career
end
Job Model
class Job < ActiveRecord::Base
belongs_to :user
has_many :descriptions
end
Controller
def show
@user = User.find(1)
end
What is the best way to go about this? I was able to display other elements such as Name and Contacts on the same Show View page. I have tried a ton of different lines but currently have this...
Show View
<%= @user.jobs.first.title %>