# Designing a data-entry screen

**URL:** <https://www.ruby-forum.com/t/designing-a-data-entry-screen/73109>\
**Category:** Rails\
**Created:** [December 20, 2005, 5:36am UTC](https://www.ruby-forum.com/t/designing-a-data-entry-screen/73109 "2005-12-20T05:36:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [December 20, 2005, 5:36am UTC](https://www.ruby-forum.com/t/designing-a-data-entry-screen/73109/1 "2005-12-20T05:36:00Z")

</div>

Here’s what i’m trying to do:

Have 3 dropdowns up the top of a page, being: year, month, department,  
and group. Also a button underneath that called refresh.  
When you click refresh, it finds the 1 row of data from the database for  
that year/month/dept/group and populates the fields into a set of  
textboxes below.  
Then you can edit what is in those textboxes, and click a ‘save’ button,  
and it’ll update the record back into the database.

Here’s what i’m struggling getting to work:

How do you get the dropdowns up the top to keep their values after the  
postback?  
How do you access the values in those dropdowns from the controller?  
How do you get the controller to perform different actions when they  
click ‘refresh’ versus clicking ‘save’ ?

I’m a bit of a beginner, but i believe rails stands a good chance of  
revolutionising my productivity, eventually when i get the hang of it! I  
already know how to do all this in [asp.net](http://asp.net) but i’m keen to learn rails.

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [December 20, 2005, 1:45pm UTC](https://www.ruby-forum.com/t/designing-a-data-entry-screen/73109/2 "2005-12-20T13:45:15Z")

</div>

i might try something like this

(untested)

controller:

def do\_form  
if @request.method == “post”  
# load the department and group from the values submitted  
# you will need them to be able to have the values selected  
# when you redisplay the form  
@department = Department.find(@params[:department][:id])  
@group = Group.find(@params[:group][:id])  
if @params[:commit] == “Refresh”  
# do your refresh stuff here  
elsif @params[:commit] == “Save”  
# do your save here  
end  
end

# data to populate select tags

# @years = (1970…2005).to\_a # @ years = [1970, 1971, 1972, … 2005] @months = (1…12).to\_a # @months = [1, 2, 3, … 12] @depts = Department.find(:all).collect { |d| [d.name, d.id] } # @depts

[[“dept 1”, 1], … ]  
@groups = Group.find(:all).collect { |g| [g.name, g.id] } # #groups =  
[[“group 1”, 1], … ]  
end

do\_form.rhtml:

\<%= start\_form\_tag :action =\> :do\_form %\>  
Year: \<%= select\_tag “year”, options\_for\_select(@dates, @params[:year])  
%\>  
  
Month: \<%= select\_tag “month”, options\_for\_select(@months,  
@params[:month])  
%\>  
  
Dept: \<%= select “department”, “id”, @depts %\>  
  
Group: \<%= select “group”, “id”, @groups %\>  
  
\<%= submit\_tag “Refresh” %\>\<%= submit\_tag “Save” %\>  
\<%= end\_form\_tag %\>

hope this helps

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [December 20, 2005, 10:53pm UTC](https://www.ruby-forum.com/t/designing-a-data-entry-screen/73109/3 "2005-12-20T22:53:02Z")

</div>

Thanks a lot! You’re a champion.
