简体   繁体   中英

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!

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

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM