? concerning ActiveRecord, Action and template

Much appreciate any help here. I’m just getting started learning RoR and
setting up my first form is throwing me - I’m not getting the concepts
formalized in my mind.

Situation:

  • Controller is: Donation
  • Action is: donation_entry
  • Template is: donation_entry.rhtml

This form will be displayed when selected from sidebar menu (which will
always be present for all forms). As such it will be blank for adding a
record.

This form will also be displayed when selecting a donation record from
another form, in which case the record selected will be displayed as
well.

My understanding is that I need a template/form named
donation_entry.rhtml, which I have, but I also need a template/form for
every action in my controller.

I don’t want this.

What I want is this:

Scenario One:

User selects Donation from sidebar menu. Blank form is displayed, user
enters data and hits submit. Record is added to the database and form
remains displayed with data just entered as is - allowing updating.

Scenario Two:

User selects this record off list in another form. Donation_entry form
is displayed with this record. User modifies data and hits submit. The
record is left displayed on form as is - same as when adding a record.

Question:

In DonationController, action method donation_entry, couldn’t I do the
following, thus avoiding two or three templates/forms - one for each
action, if I have just the one action of donation_entry:

def donation_entry (in psuedo code)
if new_record
add record
else
if save record
save_record
else
if update_record
update_record
end

In case you are wondering, if the user wanted to immediately add a
second donation record, they would select Donation off the sidebar menu.

I hope this is sufficient information. Any help is very much
appreciated.

Thanks in advance.

Kee (Scott)

Sounds fairly simple. You want the form to be shared across multiple
actions. Correct? What you want is a partial that contains your form.
Check
out out wiki, and other tutorials on www.rubyonrails.com. Partials are
used
a lot, and are very handy.

-Nick

p.s. If you generate scaffolding it uses partials for all its stuff. I
would
recommend studying that code and see how its done. Scaffolding is a
great
place to start learning.

Thank you Nick. I will give it a shot.

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