Designing a data-entry screen

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
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 but i’m keen to learn rails.

i might try something like this



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

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| [,] } # @depts

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


<%= start_form_tag :action => :do_form %>
Year: <%= select_tag “year”, options_for_select(@dates, @params[:year])

Month: <%= select_tag “month”, options_for_select(@months,

Dept: <%= select “department”, “id”, @depts %>

Group: <%= select “group”, “id”, @groups %>

<%= submit_tag “Refresh” %><%= submit_tag “Save” %>
<%= end_form_tag %>

hope this helps

Thanks a lot! You’re a champion.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs