Introducing first name and last name as listing attribute

I would like to make my listing index and show page displaying the first name and last name (first letter only) and gave it an attempt. Originally, the code was <h3><%= listing.user.name %></h3> I tried to change it to <h3><%= "#{listing.user.first_name.capitalize} #{listing.user.last_name.capitalize[0]}."</h3> Have I gone wrong somewhere as it didn't work?

Posted about 5 years ago by Harry Lee
Posted about 5 years ago by Alex Yang

What did you see instead?

0
Posted about 5 years ago by Harry Lee

Sorry i forgot the close ruby tag at the end! fixed now:)

0
Posted about 5 years ago by Harry Lee

So there is an error again. I've created a scaffold called Tutor. In the index I'm displaying a list of tutors with their first and last name, university, subject... But I was hoping to use the user's first and last name in the tutor index and show file and didn't create first name and last name columns. Is it possible to do such or do i need to create first and last name columns in tutor table?

If possible, what should i change in
<h3><%= "#{user.first_name} #{user.last_name.capitalize[0]}." %></h3>

because it says undefined method 'user'

0
Posted about 5 years ago by Alex Yang

Best to create the first and last name columns. And try using 'current_user' instead of 'user'.

0