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 trial
Giann Wilkerson
6,897 PointsFriend required Message after "fixing the new.html.erb" file
Hi,
I was wondering if anyone else had issues with the part in the video "integration testing friendships " where after you updated the new.html.erb file and you click "add as friend " it still says the error message "friend required." I dont get the message as they do on the video that the friendship has been created. Can anyone offer any advice?
14 Answers
Jason Seifer
Treehouse Guest TeacherHi Giann Wilkerson can you post your new.html.erb file here? And the new method in the user friendships controller?
Giann Wilkerson
6,897 Points<% if @friend %>
<h1><%= @friend.full_name %></h1>
<p>Do you really want to friend <%= @friend.full_name %>?</p>
<%= form_for @user_friendship,method: :post do |form| %>
<div class="form from-actions">
<% form.hidden_field :friends_id, value: @friend.profile_name %>
<%= submit_tag "Yes, Add Friend", class: 'btn btn-primary' %>
<%= link_to "Cancel", profile_path(@friend), class: 'btn' %>
</div>
<% end %>
<% end %>
def new
if params[:friend_id]
@friend = User.find(params[:friend_id])
@user_friendship = current_user.user_friendships.new(friend: @friend)
else
flash[:error] = "Friend required"
end
rescue ActiveRecord::RecordNotFound
render file: 'public/404', status: :not_found
end
Hopefully this is what you needed. Let me know if you need more. Thank you Jason.
Jason Seifer
Treehouse Guest TeacherIt looks like you need to change the controller to the following:
if params[:user_friendship] && params[:user_friendship].has_key?(:friend_id)
...
Giann Wilkerson
6,897 PointsJason,
Thanks buddy You are the man!
Although, this brings rise to my previous error. Im getting the message "friend required." instead of you are now friends with ... I remember you hit that step in the video, and you solved it. I did exactly what you did and im still receiving that error.
Jason Seifer
Treehouse Guest TeacherCan you post your code up on GitHub and I'll take a look?
Giann Wilkerson
6,897 PointsJason,
I have it up on Github. My username is GIannWilk. Do you need anything else to take a look at it?
Jason Seifer
Treehouse Guest TeacherHey Giann Wilkerson try changing your user friendships controller new method to this and everything should work:
def new
if params.has_key?(:friend_id)
@friend = User.find_by_profile_name(params[:friend_id])
@user_friendship = current_user.user_friendships.new(friend: @friend)
else
flash[:error] = "Friend required"
end
rescue ActiveRecord::RecordNotFound
render file: 'public/404', status: :not_found
end
Sorry for the trouble! Looks like I told you the wrong thing above.
Giann Wilkerson
6,897 PointsJason,
Thanks so much for taking time to investigate this matter. Although, (sorry to say this) upon uploading the code and saving and launching everything in rails, everything works up until i get to the part where i click "yes, im sure i want to be friends with .." after this, I get a page that gives the yellow flash error "friend required." I still cannot successfully establish a friend relationship through the API.
P.S I really appreciate all the help and support you guys offer.
Giann Wilkerson
6,897 PointsHi Jason Seifer, I was wondering if you had a chance to look into the above issue. If you could offer some advice or a direction that would be perfect and much appreciated, Thanks!
Jason Seifer
Treehouse Guest TeacherHi Giann Wilkerson sorry about that! I think I need to see your code to troubleshoot the issue. Can you push the latest version up to GitHub and I'll take a look?
Kirushi Arunthavasothy
1,621 PointsI have run into similar problem, and was looking at this thread hoping for a solution.
Sadly to see that the responses were cut short. Perhaps it was handled elsewhere?
Giann Wilkerson
6,897 PointsNo problem. Thank you for taking a look. If you could let me know what the issue is, i would greatly appreciate it so that i can try to learn from the mistakes. Thanks, Ive updated and pushed the current version to GitHub.
Giann Wilkerson
6,897 PointsHi Jason,
Just Wanted to follow up with you. Please let me know if I can provide further details.
Thanks
Giann Wilkerson
6,897 PointsHi Josh,
Im actually still stuck at this point. Jason was helping me and I assume he got extremely busy. (Never heard a response.) I would be very interested to understand what I did wrong or to get a resolution.
Jason Seifer
Treehouse Guest TeacherHey Giann Wilkerson sorry about that! I lost track of this thread. What are you stuck on? I'll try and help out.
Giann Wilkerson
6,897 PointsHey Jason Seifer , No worries. I know you have been busy with all the new treehouse content. I was having issues with " integration testing friendship." I updated the new.html.erb file and if you click "add as friend " it still says the error message "friend required." I dont get the message as they do on the video that the friendship has been created.
I have my recent/current files updated on Git. I would appreciate any help you could provide. Please let me know if there is anything I need to do.
Thanks,
Giann Wilkerson
6,897 PointsHey Jason Seifer
Wanted to see if you had a chance to take a look at my files and could offer any suggestions to help me get back up and running?
Jason Seifer
Treehouse Guest TeacherHey Giann Wilkerson the problem is here:
https://github.com/giannwilk/treebook/blob/master/app/views/user_friendships/new.html.erb#L8
You'll need to change it from <% to <%= to get the friend_id parameter in the form. Give that a try and let us know if it works.
Giann Wilkerson
6,897 PointsThanks for the reply Jason Seifer I made that update although I'm still receiving the "friend required" yellow error message after clicking the "Yes, Add Friend" button. Any suggestions?