Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRoss Litzenberger
11,706 PointsRails 4 working with devise need to have user connent to its jobs
So i am stuck right now.... I am using devise. i want to have to user that posted the job display the first_name and last_name but all i am getting in the user_id. here the github account https://github.com/RossLitzenberger/Jobboard
3 Answers
Ross Litzenberger
11,706 PointsI just pulled down my application again
- rake db:create
- rake db:migrate 3 .When to app/views/jobs/show.html.haml . add @job.user.first_name @job.user.last_name
%p#notice= notice .job_show .job_header
.show_job_title
= @job.title
.company_name
= @job.company_name
-# here the question i want to display the user that goes with the job that get posted.
.user
-if user_signed_in?
Posted by
= @job.user.first_name
= @job.user.last_name
.job_date
POSTED ON
%br
= @job.created_at
%p.job_description
= @job.description
= link_to 'Show More', @job.details_link, :class => "details_link"
.job_links
= link_to 'Edit', edit_job_path(@job)
|
= link_to 'Back', jobs_path
- run rails s
- open the browers
- click register (build a user filled out everything)
Stop! open rails console and type User.first I saw that first_name last_name profile_name is "ni "but everything else was entered in
- Create a Job post
- I submit it
- the Posted by is not showing the first_name last_name profile_name
why are those field nil . when i fill all that out in register?
Maciej Czuchnowski
36,441 PointsDid you include first_name and last_name as permitted attributes for mass assignment? If not, they are not saved in the database and are therefore nil.
Ross Litzenberger
11,706 Pointsthanks for everyone help it works now ! :)
Ross Litzenberger
11,706 PointsHow do i not allow other user to edit other users posts?
Maciej Czuchnowski
36,441 PointsIf you're using Devise, you should check if the user that clicked the edit link (current_user) is the same user as the one who created it (post.user). If he's not, then redirect and flash an error.
Fabion Stephens
Courses Plus Student 5,893 PointsFabion Stephens
Courses Plus Student 5,893 PointsI'm not seeing how you are actually saving the user info to the database. Can you please let me know how you are doing that? Or is that you are manually inserting the records into your database?
Also what happened when you getting the user first and last name like so?
@job.user.first_name @job.user.last_name