嗨,我目前在提交创建相册的表单时在控制器中收到错误消息。这是我的第一个项目,我对控制器以及要放置的参数以及将实例变量设置为的内容非常不稳定......请帮助!
在提交我的 new.html.erb 表单时,我收到
ActiveRecord::RecordNotFound in AlbumsController#create
找不到没有 ID 的用户
这是我的相册控制器
class AlbumsController < ApplicationController
def index
@albums = Albums.all
respond_to do |format|
format.html
format.json { render json: @albums }
end
end
def show
@albums = Album.all
@album = Album.find(params[:id])
@photo = Photo.new
end
def update
end
def edit
end
def create
@user = User.find(params[:user_id])
@user.album = Album.new(params[:album])
respond_to do |format|
if @user.album.save
format.html { redirect_to @user, 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 new
@user = User.find(params[:user_id])
@album = Album.new
end
def destroy
end
end
这是我提交的表格
<%= form_for (@album), :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 %>
如果您需要更多文件,请告诉我。