没有路由匹配{:action =>“bands”,:controller =>“users”}

时间:2012-12-13 00:01:21

标签: ruby-on-rails routing rails-routing

当用户注册我的网站时,他们会被重定向到“/ welcome”,其中包含以下链接:

<%= link_to "Create Band Page", bands_user_path %>
<%= link_to "Complete Profile", edit_user_path(current_user) %>

“完整档案”链接显示并正常运行。但是,页面不会显示“创建乐队页面”链接,并导致此错误:

No route matches {:action=>"bands", :controller=>"users"}

我在用户页面上有这个链接,并且工作正常。

我的users_controller包括这一位:

def bands
  @band = current_user.bands.build
  @bands = current_user.bands.all
  @user = current_user
end

相关的routes.rb部分如下所示:

resources :users do
  member do
    get :following, :followers, :bands
  end
end
match '/welcome', to: 'static_pages#welcome'

正如我之前所说,当我在用户的节目页面上使用该链接时,它工作正常,并且rake路由包括相应的链接:

bands_user GET    /users/:id/bands(.:format)      users#bands

我在这里缺少什么?

1 个答案:

答案 0 :(得分:0)

你没有传递给你想要显示乐队的用户。

您的路线与/users/:id/bands(.:format)匹配。格式是可选段(括号的含义),但:id是必需的。它希望您传入有效的user_id或用户对象以从。

中反映user_id

试试<%= link_to "Create Band Page", bands_user_path(current_user) %>,它应该有用。

相关问题