Swap Values via Model in an onChange Event Within submit_tag Helper?

I’m new to RoR and (and programming) and am having trouble wrapping my
head around how to get this working. What I’m trying to do is autofill
a web form with values I select from a drop-down menu. I want to pull
these values in from my Openers table.

My DB Model is called Openers and has the following fields:


My Controller is called bar_controller.rb and contains only 1 method
which pulls all the records from Openers and orders them by

class BarController < ApplicationController

def bar
@show_openers = Opener.find(:all, :order => “description”)


I have 3 Views located user app/views/bar that make up a 2 column
framed page. The first file is called index.html.erb and sets up the

The second file is called bar.html.erb and fills in the upper portion
(top 10% of the page).

<%= javascript_include_tag :defaults %>

<% form_for :bar, :url => { :action => :bar } do |form| %>
<%= collection_select(“openers”, “opener_id”,
@show_openers, :id, :description ) %>
<%= submit_tag “insert opener”,
:onClick =>
parent.formtofill.document.form1.messagebody.value=‘HERE_IS_BODY’” %>
<% end %>

The last file is called formtofill.html.erb and fills in the bottom
90% of the page. It contains the form that I want to auto-populate
with the values defined in bar.html.erb.



Right now I’ve got the descriptions populating the dropdown and the
onClick will stuff the static HERE_IS_SUBJECT and HERE_IS_BODY into
the correct form fields, but there are still a few things I’m having
trouble with:

  1. How do I access the subject and body info?
  2. Once question 1 is solved, how do I update the HERE_IS_SUBJECT and
    HERE_IS_BODY values on an onChange event (within the submit_tag
    helper) with the matching Openers.subject and Openers.body values for
    the Openers.description selection?

Thanks in advance for any help!!!

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