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| %>
<%= 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 => “Event auto-saved at #{Time.new}”
end