I have a form which takes users information and stores it in the database. For some of the fields the user can put new information in a field, or select previous info from the database. It was working earlier, however I recently cleaned the database and now I get this error when I try to access the page.
undefined method `empty?' for nil:NilClass
Extracted source (around line #27):
27: <%= f.select( :client, Project.all.map {|p| [p.client]}.uniq!, :prompt => "Select a previous Client") %>
Form view example:
<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>
Project Controller:
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
UPDATE:
I think the error is coming from the .uniq! method in my form view. Any other ideas?
Thanks