我有一个表单,它获取用户信息并将其存储在数据库中。对于某些字段,用户可以将新信息放入字段中,或从数据库中选择以前的信息。它之前工作过,但是我最近清理了数据库,现在当我尝试访问该页面时出现此错误。
未定义的方法“空?” 对于零:NilClass
提取的源代码(在第 27 行附近):
27: <%= f.select( :client, Project.all.map {|p| [p.client]}.uniq!, :prompt => "选择以前的客户端") %>
表单视图示例:
<div class="field">
<%= label_tag :new_client, "Client" %><br/>
<%= text_field_tag :new_client %>
Or
<%= f.select( :client, Project.all.map {|p| [p.client]}.uniq!, :prompt => "Select a previous Client") %>
</div>
项目负责人:
def create
@project = Project.new(params[:project])
@project.client = params[:new_client] unless params[:new_client].empty?
@project.exception_pm = params[:new_exception_pm] unless params[:new_exception_pm].empty?
@project.project_owner = params[:new_project_owner] unless params[:new_project_owner].empty?
@project.role = params[:new_role] unless params[:new_role].empty?
@project.industry = params[:new_industry] unless params[:new_industry].empty?
@project.business_div = params[:new_business_div] unless params[:new_business_div].empty?
respond_to do |format|
if @project.save
format.html { redirect_to @project, notice: 'Project was successfully created.' }
format.json { render json: @project, status: :created, location: @project }
else
format.html { render action: "new" }
format.json { render json: @project.errors, status: :unprocessable_entity }
end
end
end
更新:
我认为错误来自.uniq!我的表单视图中的方法。还有其他想法吗?
谢谢