I’m creating a timesheet application where a “Timesheet” object has 7
“TimesheetDays” objects. Everything works fine until error validation
or a ‘preview’ (after calculations) when the form is re-rendered. The
data in the fields for the Timesheet object persist after render, but
all my text input fields for each of the TimesheetDay objects reset. I
know I’m doing something wrong here, but I need the data the use
entered into the TimsheetDay fields to remain. Please help!!
same question i asked, but i couldn’t state it properly. asked the
question twice.
i have tried several things but can not get it to work.
tried several ways of getting params data to a instance variable. i
was using a fields_for like this…
<% fields_for “second_model”, @second_info do | second_form | %>
Yes, Ruby F., the data isn’t saved, but in “Preview Mode” for
calculating totals before confirming. I don’t think that’s the problem
because the Timesheet attributes persist, only the TimesheetDay object
attributes are cleared. Maybe I need to add the user-entered data to a
cookie or the session?
I’m tempted to just hard-wire the entire timesheet into a 1 week deal,
but it seems hackish to me. I’m going to the Pragmatic Programmers
Advanced Rails workshop next week. I’ll ask them and update my post.
This might be a stupid observation, but isn’t your code falling out to
render :action => ‘new’ before save ever gets called?
def create
week_select @timesheet = Timesheet.new(params[:timesheet])
if params[:calculate]
run_calculations
render :action => ‘new’ #code is falling out here and never
running save
elsif [email protected]
render :action => ‘new’
elsif @timesheet.save
# some stuff…
end