Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8694415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:46:58+00:00 2026-06-13T00:46:58+00:00

I have an app that allows users to enter a project into a database.

  • 0

I have an app that allows users to enter a project into a database.

They get the option to either enter new data via a textbox for some field, or can select data via a drop down menu, that has been entered before for that field.

If the user fills out the form, then clicks submit, but there is a problem, like they have missed out one of the fields, the page flags up an error saying which fields are missing, which is fine.

However, if the user had entered new data in the text boxes, that gets deleted, and the first option in the drop down is selected instead.

Here is my project controller:

class ProjectsController < ApplicationController


before_filter :authenticate_user!
#:except => [:show, :index]




    def index
        @projects = Project.all

respond_to do |format|
      format.html # index.html.erb
      format.json { render :json => @projects }
    end
  end

  # GET /projects/1
  # GET /projects/1.json
  def show
    @project = Project.find(params[:id])
        @project_project_id = params[:id]

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @project }
    end
  end

  # GET /projects/new
  # GET /projects/new.json
  def new
    @project = Project.new
        @technol = Technol.new(params[:tech])

        @all_technols = Technol.all
        tech_ids = params[:technols][:id].reject(&:blank?) unless params[:technols].nil?


        @project_technol = @project.projecttechnols.build

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @project }
    end
  end

  # GET /projects/1/edit
  def edit
    @project = Project.find(params[:id])
        @project_technol = @project.projecttechnols.build



puts @project.inspect
puts @project.technols.inspect
  end

  # POST /projects
  # POST /projects.json
  def create    
    @project = Project.new(params[:project])
        @project.client = params[:new_client] unless params[:new_client].blank?
        @project.role = params[:new_role] unless params[:new_role].blank?
        @project.industry = params[:new_industry] unless params[:new_industry].blank?
        @project.business_div = params[:new_business_div] unless params[:new_business_div].blank?


if !params[:technols].nil?

            params[:technols][:id].each do |tech|

                if !tech.empty?

                    @project_technol = @project.projecttechnols.build(:technol_id => tech) 

                end
            end

end

    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

  # PUT /projects/1
  # PUT /projects/1.json
  # PUT /projects/1
  # PUT /projects/1.json
  def update


    @project = Project.find(params[:id])

puts @project.inspect
puts @project.technols.inspect
        @project.client = params[:new_client] unless params[:new_client].blank?
        @project.role = params[:new_role] unless params[:new_role].blank?
        @project.industry = params[:new_industry] unless params[:new_industry].blank?
        @project.business_div = params[:new_business_div] unless params[:new_business_div].blank?


    respond_to do |format|
      if @project.update_attributes(params[:project])
        format.html { redirect_to @project, notice: 'Project was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @project.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /projects/1
  # DELETE /projects/1.json
  def destroy
    @project = Project.find(params[:id])
    @project.destroy

    respond_to do |format|
      format.html { redirect_to projects_url }
      format.json { head :no_content }
    end
  end




private

  helper_method :sort_column, :sort_direction
  def sort_column
    Project.column_names.include?(params[:sort]) ? params[:sort] : "project_name"
  end

  def sort_direction
    %w[asc desc].include?(params[:direction]) ? params[:direction] : "asc"
  end

    def per_page
      params[:per_page] ||= 1
    end
    def page 
      params[:page] ||= 1
   end
end

Here is some of my new project view

<%= stylesheet_link_tag "new" %>


<h1>Create New Project</h1>
<HTML>

<%= stylesheet_link_tag "form" %>


<%= form_for(@project) do |f| %>


  <% if @project.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@project.errors.count, "error") %> prohibited this project from being saved:</h2>

      <ul>
      <% @project.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

<CENTER>

   <div id = "project_name">
<div class="project_name">
    Project Name:
    <%= f.text_field :project_name,:maxlength => 30 %>
  </div>
</div>


   <div id ="smallbox">
<div id = "status">
  <div class="status"> 
    <%= f.label :status %> : 

    <%#= f.select :status, [['Active'],['Completed']], {:include_blank => true} %>
    <%= f.select :status, [['Active'],['Completed']] %>
  </div></div> 



<div class="client" STYLE="text-align: left;">
<%= label_tag :new_client, "Client" %><br/>
<%= text_field_tag :new_client, nil, :maxlength => 30 %>
Or
<%= f.select( :client, Project.all.map {|p| [p.client]}.uniq, :prompt => "Select previous..") %>
</div>


   <div class="business_div" STYLE="text-align: left;">
<%= label_tag :new_business_div, "Business Division" %><br/>
<%= text_field_tag :new_business_div, nil, :maxlength => 30 %>
Or
<%= f.select( :business_div, Project.all.map {|p| [p.business_div]}.uniq, :prompt => "Select previous") %>
</div>

   <div class="start_date" STYLE="text-align: left;">
    <b>Start Date:</b>
    <%= f.text_field :start_date, :class => 'datepicker', :style => 'width: 80px;' %>
  </div>  

</P>


<div class="create_button">
<div class="actions">
    <%= f.submit "Save New Project", :class => "button",  :confirm => "Are you sure you want to save the new project?" %>
  </div>
</div>

</div> <%#= small div %>


<% end %>



<div class="back_button2">
<%= button_to "Back", projects_path , :class => "button", :method => "get" %>
</div>

Here is my project model

class Project < ActiveRecord::Base
  attr_accessible  :fullname, :edited_first_name, :edited_last_name, :first_name, :last_name, :business_div, :client, :customer_benefits, :edited_date, :end_date, :entry_date, :financials, :industry, :keywords, :lessons_learned, :project_name, :role, :start_date, :status, :summary, :technol_ids, :tech , :technols



validates_presence_of :business_div, :client, :customer_benefits, :end_date, :financials, :industry, :lessons_learned, :project_name,  :role, :start_date, :status, :summary #, :keywords

validates_format_of :industry, :with => /\A[^\d]+\Z/, :message => "field should only have letters"
validates_format_of :business_div, :with => /\A[^\d]+\Z/, :message => "field should only have letters"
validates_format_of :client, :with => /\A[^\d]+\Z/, :message => "field should only have letters"
validates_format_of :exception_pm, :with => /\A[^\d]+\Z/, :message => "field should only have letters"
validates_format_of :project_owner, :with => /\A[^\d]+\Z/, :message => "field should only have letters"
validates_format_of :role, :with => /\A[^\d]+\Z/, :message => "field should only have letters"

has_many :projecttechnols
has_many :technols, :through => :projecttechnols

  def set_fullname(a, b)
    fullname = [a, b].join(' ')
  end


accepts_nested_attributes_for(:technols)

end

If I need to include anything else please let me know. I have been stuck with this problem for some time now. Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:46:59+00:00Added an answer on June 13, 2026 at 12:46 am

    As railsdog suggests, use the data passed to Projects#create. Your form submits data and that data is held in a variable called params as key/value pairs. That variable should still be accessible from whichever view Projects#create renders.

    What you need to do is to set some default content on your form elements. Here’s an example for the text_field called “project_name”

    <div class="project_name">
     Project Name:
      <%= f.text_field :project_name, params[:project_name],:maxlength => 30 %>
    </div>
    

    You should be able to do the same or something similar with any other fields.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that allows users to upload large data files and then
I have an app that allows users to enter, edit and search for projects
I have an iPhone app that allows users to record videos and I'd like
I have a topics app that allows users to create topics. For each individual
We have a WPF app that allows our users to download encrypted content and
I'm creating a web app that allows users to enter a number of colors,
I wrote an app that allows the user to enter data in a UITextField,
I have an app that allows users to win prizes. To win a prize
I have a relatively simple web app, that allows the user to enter two
I have an app that allows the user to choose an image, at design

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.