현재 사진을 업로드하는 프로젝트를 진행 중입니다. 해당 앨범에는 사용자, 앨범 및 그림이 있습니다. 나는 앨범으로 사용자를 만들 때까지 (세션, 인증 또는 아직 로그인하지 않았지만 등록을 마쳤습니다). 나는 내 new.html.erb의 URL이 괜찮다는 것을 알 수레일 : ActiveRecord :: RecordNotFound - ID없이 사용자를 찾을 수 없습니다.
Couldn't find User without an ID
레일 내 양식 제출 후 오류를 수신하지 해요 :
http://localhost:3000/users/13/albums/new
(문제)
하지만, 내가 제출 한 후, 그것은 나에게 오류를 제공하고, 페이지는 다음과 같습니다
http://localhost:3000/albums/58
(. 문제 URL에 어떤 USER_ID)
누군가 내 루트가 방금 왜 갑자기 변했고 어떻게 고쳐야하는지 알 수 있습니까? 오류는 내 app/controllers/albums_controller.rb : 14 : @user = User.find (params [: user_id]) 행을 '표시'합니다.
new.html.erb
<%= form_for (@album), url: user_albums_path, :html => { :id => "uploadform", :multipart => true } do |f| %>
<div>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :description %>
<%= f.text_area :description %>
<br>
<%=f.submit %>
</div>
<% end %>
albums_controller
def show
@user = User.find(params[:user_id])
@album = @user.albums.find(params[:id])
@photo = @album.photos.build(params[:photo])
respond_to do |format|
if @user.save
format.html { redirect_to album_photo_path(@album), notice: 'Album was successfully created.' }
format.json { render json: @album, status: :created, location: @album}
else
format.html { render action: "new" }
format.json { render json: @album.errors, status: :unprocessable_entity }
end
end
end
def update
end
def edit
end
def create
@user = User.find(params[:user_id])
@album = @user.albums.build(params[:album])
respond_to do |format|
if @user.save
format.html { redirect_to @album, notice: 'Album was successfully created.' }
format.json { render json: @album, status: :created, location: @album}
else
format.html { render action: "new" }
format.json { render json: @album.errors, status: :unprocessable_entity }
end
end
end
루트
Pholder::Application.routes.draw do
resources :users do
resources :albums
end
resources :albums do
resources :photos
end
당신이 대답을 본 적이 있나요? http://stackoverflow.com/questions/1303980/activerecordrecordnotfound-couldnt-find-user-without-an-id?rq=1 –
예전에 이미 보았지만 나에게는 아무 것도하지 않았습니다. 같은 오류 – Edmund
나는 문제가 내 앨범 # 리디렉션을 만드는 것 같아요 ... – Edmund