I''m trying to write a mechanism to allow a user to input information
about a phone call, including timestamps and various events, among other
things. When a user clicks the New Call link from the main page, the New
Call view is rendered and the ''new'' method in the controller
is invoked
which creates a new row (record) in the ''calls'' table of the
database.
The New Call view has a drop-down menu and a text area for user input,
as well as other Ajax-enabled controls. When the user makes a selection
from the drop-down menu and enters text in the text area and presses the
Submit button, the ''newEvent'' method creates a new row in the
''comments''
table of the database.
I''ve tried many things and still cannot get the new row in the
''events''
table associated with the row in the ''calls'' table. I need to
do this so
I can display to the viewer that event X belongs to call Y.
How can I do this??
In the view:
<% form_for :call, @call, :url => { :action => "newEvent" },
:html =>
{:id => ''post_event''} do |f| %>
<select name="comment[event_id]">
<option></option>
<% @event.each do |event| %>
<option value="<%= event.id %>"><%=
event.eventtype %></option>
<% end %>
</select>
<!-- data from here is entered into comments table, comment column -->
<%= text_area :comment, :comment, :class=>"large" %>
<%= submit_tag "Save Event" %>
<% end %>
In the controller:
def newEvent
#carry over the session variable created in
#method ''new'' like so... session[:call_id] = @call.id
@call = Call.find_by_id(session[:call_id])
@event = Event.find(:all)
@comment = Comment.new(params[:comment])
if @comment.save
flash[:notice] = ''Successfully added event to dispatch
call''
redirect_to :action => ''list''
end
end
def save_event
session[:post_event] = Call.new(params[:event])
render :text => "<em>Event auto-saved at
#{Time.new}</em>"
end
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---