繁体   English   中英

rails 4.1.6在似乎没有显示的rake路由中添加索引

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

嗨我有一个问题,因为索引似乎没有在我的佣金路线正确显示

我已经在我的控制器模块中定义了索引

def index
    @user_friendship = current_user.user_friendships.all
end

我还在视图中将其定义为index.html.erb

但我的问题是它现在显示在我的佣金路线中这是我唯一得到的

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

你可以看到它并没有显示在我的佣金路线上

这是我对routes.rb的代码

resource :user_friendships do
  member do
    put :accept
  end
end

如果你们可以帮我解决这个问题,那将会很棒,请注意我是一个铁杆初学者,只是按照我朋友给我的教程,所以我在修复教程附带的错误方面遇到了麻烦这看起来有点老了,再次感谢!

默认情况下, resource不会创建索引操作。 你应该使用resources

resources :user_friendships do
  member do
    put :accept
  end
end

Differences between resource and resources

尝试使用resources而不是resource 默认情况下, resource不会创建索引操作,而是可以明确地将其表示为ie。 resource only: [:index, :show, :edit]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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