0
안녕하세요, 내 중첩 된 리소스를 처음 사용합니다. rake routes
을 수행하고 new_user_album_path에 대한 경로를 찾았지만 작동하지 않습니다. 내가 이중 둥지를했기 때문에 문제가 될 수 있습니까?레일에 중첩 된 리소스에 대한 경로 오류가 없습니다.
문제는 특히 show.html.erb라는 사용자보기 파일에서 링크를 클릭 할 때 발생합니다.
show.html.erb
<% provide(:title, "Welcome, #{@user.name}!") %>
<div>
You currently have <%= pluralize(@user.albums.count, "album") %>
</div>
<div>
<%= link_to "Create a new album!", new_user_album_path %>
</div>
<div>
<% if @user.albums.any? %>
hey
<% else %>
boo
<% end %>
</div>
<%= link_to "Back", users_path %>
: 여기 No route matches {:action=>"new", :controller=>"albums"}
내 파일입니다 :는 "앨범을 만들"페이지에 연결하려고하지만 그 것은 그것은 나에게 오류를 표시 할 때 구성/라우트
Pholder::Application.routes.draw do
resources :users do
resources :albums do
resources :pictures
end
end
컨트롤러
class AlbumsController < ApplicationController
def index
@albums = Albums.all
respond_to do |format|
format.html
format.json { render json: @albums }
end
end
def new
@user = User.find(params[:user_id])
end
end
감사합니다! 젠장, 생각보다 쉬웠 어. – Edmund
일반적인 실수. 라우팅 오류는 다형성 때문에 해독하는 법을 배워야하는 것 중 하나입니다. 이 경우 정의되지 않은 변수를 전달하면 존재하지 않는 다른 경로가 검색됩니다. – numbers1311407