Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails 4.1.6 adding index in rake routes that seems to be not showing

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!

like image 501
user1868185 Avatar asked Nov 21 '25 06:11

user1868185


2 Answers

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

like image 121
Philidor Avatar answered Nov 22 '25 22:11

Philidor


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]

like image 42
borfd Avatar answered Nov 22 '25 22:11

borfd