3

Hi i have a bit of a problem as to the index doesnt seem to show properly in my rake routes

I have defined the index in my controller module like so

def index
    @user_friendship = current_user.user_friendships.all
end

and i also defined it in the view as index.html.erb

but my problem is that it is now showing in my rake routes this is what i only get

accept_user_friendships PUT /user_friendships/accept(.:format)            user_friendships#accept
user_friendships POST       /user_friendships(.:format)                   user_friendships#create
new_user_friendships GET    /user_friendships/new(.:format)               user_friendships#new
edit_user_friendships GET   /user_friendships/edit(.:format)              user_friendships#edit
                     GET    /user_friendships(.:format)                   user_friendships#show
                     PATCH  /user_friendships(.:format)                   user_friendships#update
                     PUT    /user_friendships(.:format)                   user_friendships#update
                     DELETE /user_friendships(.:format)                   user_friendships#destroy

as you can see it isnt showing in my rake routes

here is the code i have for the routes.rb

resource :user_friendships do
  member do
    put :accept
  end
end

if you guys can help me with this one it would be great also pls note that i am a bit of a beginner in rails and just followed a tutorial that my friend gave me so i am having trouble in fixing the errors that came with the tutorial that seems a bit old, and thanks again!

user1868185
  • 899
  • 3
  • 9
  • 24

2 Answers2

7

By default resource not create a index action. You should use resources:

resources :user_friendships do
  member do
    put :accept
  end
end

Differences between resource and resources

Community
  • 1
  • 1
Roman Kiselenko
  • 43,210
  • 9
  • 91
  • 103
3

Try using resources instead of resource. resource does not create an index action by default instead you could explicitly say it to ie. resource only: [:index, :show, :edit]

borfd
  • 59
  • 2