0

When a user signs up for my site, they are redirected to '/welcome', which includes these links:

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

The 'Complete Profile' link shows up and works fine. However, the page won't display with the 'Create Band Page' link, and results in this error:

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

I have that link on the user's page and it works fine tho.

My users_controller includes this bit:

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

And the relevant routes.rb parts look like this:

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

As I said before, when I use the link on a user's show page it works fine, and rake routes includes the appropriate link:

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

What am I missing here?

4

1 回答 1

0

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

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

尝试<%= link_to "Create Band Page", bands_user_path(current_user) %>,它应该工作。

于 2012-12-13T00:11:18.923 回答