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 trialNelly Nelly
7,134 Pointsundefined method `requested?'
Hi there,
If needned here is my git repo https://github.com/knopfler81/treebook/tree/ajax_part_1
I am stuck or a couple of hours.... when passing the test while implementing ajax
I have error in the browser with the indefined methiod requested... and also
when I run ruby -I test test/controllers/user_friendships_controller_test.rb
`
I receive errors....
1) Error:
UserFriendshipsControllerTest#test_: #edit when logged in should assigns the user_friendship. :
ActionView::Template::Error: undefined method `requested?' for #<UserFriendshipDecorator:0x007fbc8b897250>
app/views/user_friendships/edit.html.erb:10:in `_app_views_user_friendships_edit_html_erb__3992153109802981145_70223896503120'
test/controllers/user_friendships_controller_test.rb:217:in `block (3 levels) in <class:UserFriendshipsControllerTest>'
2) Error:
UserFriendshipsControllerTest#test_: #edit when logged in should assigns the friend. :
ActionView::Template::Error: undefined method `requested?' for #<UserFriendshipDecorator:0x007fbc8e5d2378>
app/views/user_friendships/edit.html.erb:10:in `_app_views_user_friendships_edit_html_erb__3992153109802981145_70223896503120'
test/controllers/user_friendships_controller_test.rb:217:in `block (3 levels) in <class:UserFriendshipsControllerTest>'
3) Error:
UserFriendshipsControllerTest#test_: #edit when logged in should get the edit and return success. :
ActionView::Template::Error: undefined method `requested?' for #<UserFriendshipDecorator:0x007fbc94129bb8>
app/views/user_friendships/edit.html.erb:10:in `_app_views_user_friendships_edit_html_erb__3992153109802981145_70223896503120'
test/controllers/user_friendships_controller_test.rb:217:in `block (3 levels) in <class:UserFriendshipsControllerTest>'
35 runs, 53 assertions, 0 failures, 3 errors, 0 skips
here is my iser_friendships/edit.html.erb
<div class="page-header">
<h1>Viewing friendship</h1>
</div>
<h3><%= @user_friendship.sub_message %></h3>
<div class="form-actions">
<% if @user_friendship.requested? %>
<%= form_for @user_friendship, url: accept_user_friendship_path(@user_friendship), method: :put do |form| %>
<%= submit_tag "Accept Friendship", class: 'btn btn-primary' %>
<% end %>
<% end %>
<%= form_for @user_friendship, url: user_friendship_path(@user_friendship), method: :delete do |form| %>
<%= submit_tag "Delete Friendship", class: 'btn btn-danger' %>
<% end %>
</div>
my user_friendships_controller_test.rb (edit context)
context "#edit" do
context "when not logged in" do
should "redirect to the loggin page" do
get :edit, id:1
assert_response :redirect
end
end
context "when logged in" do
setup do
@user_friendship = create(:pending_user_friendship, user: users(:jason))
sign_in users(:jason)
get :edit, id: @user_friendship.friend.profile_name
end
should "get the edit and return success" do
assert_response :success
end
should "assigns the user_friendship" do
assert assigns(:user_friendship)
end
should "assigns the friend" do
assert assigns(:friend)
end
end
end
and my edit method from my controller user_frienship_controller.rb
def edit
@friend = User.where(profile_name: params[:id]).first
@user_friendship = current_user.user_friendships.where(friend_id: @friend.id).first.decorate
end
Thanks for your help... Steve Hunter maybe?
Nelly Nelly
7,134 PointsNelly Nelly
7,134 Pointsfound ! I added
delegate_all
to the UserFriendship decorator