ebrad
2008-Apr-30 20:06 UTC
Why doesn''t my user-entered data persist after validation/preview in my multi-model form?
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!! ### VIEW - Timesheet Form ####### <h1>New timesheet</h1> <% form_tag :action => ''create'' do %> <% if params[:calculate] %> <div id="calculated" style="border: 1px solid #ddd; padding: 5px; background: #f8f8f8;"> <p><%= @timesheet.total_week_hours %></p> <%= submit_tag "Save and Finish" %> </div> <% end %> <%= error_messages_for ''timesheet'' %> <p><label for="timesheet_week">Week: </label> <%= select ''timesheet'', ''week'', [ ["Beginning #{@last_week.to_s(:long)} (Last Week)", @last_week], ["Beginning #{@this_week.to_s(:long)} (This Week)", @this_week] ] %></p> <table class="timesheet data_fields"> <tr> <th>Day</th> <th>Time In</th> <th>Time Out</th> <th></th> <th>Time In</th> <th>Time Out</th> <th></th> <th>PTO</th> <th>Vacation</th> <th>Holiday</th> <th>Jury</th> <th>Bereav.</th> <th>Ext PTO</th> <th>Unpaid</th> <th></th> <th>Comments</th> </tr> <% 7.times do |d| %> <tr class="<%= cycle(''odd'', ''even'') %>"> <%= render :partial => ''days'', :locals => { :day => d += 1 } %> </tr> <% end %> </table> <%= submit_tag "Calculate", :name => ''calculate'' %> <% end %> ## CONTROLLER - Timesheet ###### ... def create week_select @timesheet = Timesheet.new(params[:timesheet]) if params[:calculate] run_calculations render :action => ''new'' elsif !@timesheet.save render :action => ''new'' elsif @timesheet.save # some stuff... end ... end --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
rushnosh
2008-Apr-30 20:27 UTC
Re: Why doesn''t my user-entered data persist after validation/preview in my multi-model form?
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 | %> On Apr 30, 1:06 pm, ebrad <nisguy_...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> 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!! > > ### VIEW - Timesheet Form ####### > > <h1>New timesheet</h1> > > <% form_tag :action => ''create'' do %> > > <% if params[:calculate] %> > <div id="calculated" style="border: 1px solid #ddd; padding: 5px; > background: #f8f8f8;"> > <p><%= @timesheet.total_week_hours %></p> > <%= submit_tag "Save and Finish" %> > </div> > <% end %> > <%= error_messages_for ''timesheet'' %> > > <p><label for="timesheet_week">Week: </label> > <%= select ''timesheet'', ''week'', [ > ["Beginning #{@last_week.to_s(:long)} (Last Week)", @last_week], > ["Beginning #{@this_week.to_s(:long)} (This Week)", @this_week] > ] %></p> > > <table class="timesheet data_fields"> > <tr> > <th>Day</th> > <th>Time In</th> > <th>Time Out</th> > <th></th> > <th>Time In</th> > <th>Time Out</th> > <th></th> > <th>PTO</th> > <th>Vacation</th> > <th>Holiday</th> > <th>Jury</th> > <th>Bereav.</th> > <th>Ext PTO</th> > <th>Unpaid</th> > <th></th> > <th>Comments</th> > </tr> > <% 7.times do |d| %> > <tr class="<%= cycle(''odd'', ''even'') %>"> > <%= render :partial => ''days'', :locals => { :day => d += 1 } %> > </tr> > <% end %> > </table> > > <%= submit_tag "Calculate", :name => ''calculate'' %> > <% end %> > > ## CONTROLLER - Timesheet ###### > > ... > def create > week_select > @timesheet = Timesheet.new(params[:timesheet]) > if params[:calculate] > run_calculations > render :action => ''new'' > elsif !...@timesheet.save > render :action => ''new'' > elsif @timesheet.save > # some stuff... > end > ... > end--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Roger Pack
2008-Apr-30 22:01 UTC
Re: Why doesn''t my user-entered data persist after validation/preview in my multi-model form?
make sure you''re creating an @timesheet each time On Wed, Apr 30, 2008 at 2:06 PM, ebrad <nisguy_300-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> > 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!! > > ### VIEW - Timesheet Form ####### > > <h1>New timesheet</h1> > > <% form_tag :action => ''create'' do %> > > <% if params[:calculate] %> > <div id="calculated" style="border: 1px solid #ddd; padding: 5px; > background: #f8f8f8;"> > <p><%= @timesheet.total_week_hours %></p> > <%= submit_tag "Save and Finish" %> > </div> > <% end %> > <%= error_messages_for ''timesheet'' %> > > <p><label for="timesheet_week">Week: </label> > <%= select ''timesheet'', ''week'', [ > ["Beginning #{@last_week.to_s(:long)} (Last Week)", @last_week], > ["Beginning #{@this_week.to_s(:long)} (This Week)", @this_week] > ] %></p> > > <table class="timesheet data_fields"> > <tr> > <th>Day</th> > <th>Time In</th> > <th>Time Out</th> > <th></th> > <th>Time In</th> > <th>Time Out</th> > <th></th> > <th>PTO</th> > <th>Vacation</th> > <th>Holiday</th> > <th>Jury</th> > <th>Bereav.</th> > <th>Ext PTO</th> > <th>Unpaid</th> > <th></th> > <th>Comments</th> > </tr> > <% 7.times do |d| %> > <tr class="<%= cycle(''odd'', ''even'') %>"> > <%= render :partial => ''days'', :locals => { :day => d += 1 } %> > </tr> > <% end %> > </table> > > <%= submit_tag "Calculate", :name => ''calculate'' %> > <% end %> > > ## CONTROLLER - Timesheet ###### > > ... > def create > week_select > @timesheet = Timesheet.new(params[:timesheet]) > if params[:calculate] > run_calculations > render :action => ''new'' > elsif !@timesheet.save > render :action => ''new'' > elsif @timesheet.save > # some stuff... > end > ... > end > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ruby Freak
2008-Apr-30 22:54 UTC
Re: Why doesn''t my user-entered data persist after validation/preview in my multi-model form?
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 !...@timesheet.save render :action => ''new'' elsif @timesheet.save # some stuff... end On Apr 30, 3:01 pm, "Roger Pack" <rogerpack2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> make sure you''re creating an @timesheet each time > > On Wed, Apr 30, 2008 at 2:06 PM, ebrad <nisguy_...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote: > > > 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!! > > > ### VIEW - Timesheet Form ####### > > > <h1>New timesheet</h1> > > > <% form_tag :action => ''create'' do %> > > > <% if params[:calculate] %> > > <div id="calculated" style="border: 1px solid #ddd; padding: 5px; > > background: #f8f8f8;"> > > <p><%= @timesheet.total_week_hours %></p> > > <%= submit_tag "Save and Finish" %> > > </div> > > <% end %> > > <%= error_messages_for ''timesheet'' %> > > > <p><label for="timesheet_week">Week: </label> > > <%= select ''timesheet'', ''week'', [ > > ["Beginning #{@last_week.to_s(:long)} (Last Week)", @last_week], > > ["Beginning #{@this_week.to_s(:long)} (This Week)", @this_week] > > ] %></p> > > > <table class="timesheet data_fields"> > > <tr> > > <th>Day</th> > > <th>Time In</th> > > <th>Time Out</th> > > <th></th> > > <th>Time In</th> > > <th>Time Out</th> > > <th></th> > > <th>PTO</th> > > <th>Vacation</th> > > <th>Holiday</th> > > <th>Jury</th> > > <th>Bereav.</th> > > <th>Ext PTO</th> > > <th>Unpaid</th> > > <th></th> > > <th>Comments</th> > > </tr> > > <% 7.times do |d| %> > > <tr class="<%= cycle(''odd'', ''even'') %>"> > > <%= render :partial => ''days'', :locals => { :day => d += 1 } %> > > </tr> > > <% end %> > > </table> > > > <%= submit_tag "Calculate", :name => ''calculate'' %> > > <% end %> > > > ## CONTROLLER - Timesheet ###### > > > ... > > def create > > week_select > > @timesheet = Timesheet.new(params[:timesheet]) > > if params[:calculate] > > run_calculations > > render :action => ''new'' > > elsif !...@timesheet.save > > render :action => ''new'' > > elsif @timesheet.save > > # some stuff... > > end > > ... > > end--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
ebrad
2008-May-01 18:52 UTC
Re: Why doesn''t my user-entered data persist after validation/preview in my multi-model form?
Yes, Ruby Freak, 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. On Apr 30, 6:54 pm, Ruby Freak <twscann...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 !...@timesheet.save > render :action => ''new'' > elsif @timesheet.save > # some stuff... > end > > On Apr 30, 3:01 pm, "Roger Pack" <rogerpack2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > make sure you''re creating an @timesheet each time > > > On Wed, Apr 30, 2008 at 2:06 PM, ebrad <nisguy_...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote: > > > > 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!! > > > > ### VIEW - Timesheet Form ####### > > > > <h1>New timesheet</h1> > > > > <% form_tag :action => ''create'' do %> > > > > <% if params[:calculate] %> > > > <div id="calculated" style="border: 1px solid #ddd; padding: 5px; > > > background: #f8f8f8;"> > > > <p><%= @timesheet.total_week_hours %></p> > > > <%= submit_tag "Save and Finish" %> > > > </div> > > > <% end %> > > > <%= error_messages_for ''timesheet'' %> > > > > <p><label for="timesheet_week">Week: </label> > > > <%= select ''timesheet'', ''week'', [ > > > ["Beginning #{@last_week.to_s(:long)} (Last Week)", @last_week], > > > ["Beginning #{@this_week.to_s(:long)} (This Week)", @this_week] > > > ] %></p> > > > > <table class="timesheet data_fields"> > > > <tr> > > > <th>Day</th> > > > <th>Time In</th> > > > <th>Time Out</th> > > > <th></th> > > > <th>Time In</th> > > > <th>Time Out</th> > > > <th></th> > > > <th>PTO</th> > > > <th>Vacation</th> > > > <th>Holiday</th> > > > <th>Jury</th> > > > <th>Bereav.</th> > > > <th>Ext PTO</th> > > > <th>Unpaid</th> > > > <th></th> > > > <th>Comments</th> > > > </tr> > > > <% 7.times do |d| %> > > > <tr class="<%= cycle(''odd'', ''even'') %>"> > > > <%= render :partial => ''days'', :locals => { :day => d += 1 } %> > > > </tr> > > > <% end %> > > > </table> > > > > <%= submit_tag "Calculate", :name => ''calculate'' %> > > > <% end %> > > > > ## CONTROLLER - Timesheet ###### > > > > ... > > > def create > > > week_select > > > @timesheet = Timesheet.new(params[:timesheet]) > > > if params[:calculate] > > > run_calculations > > > render :action => ''new'' > > > elsif !...@timesheet.save > > > render :action => ''new'' > > > elsif @timesheet.save > > > # some stuff... > > > end > > > ... > > > end--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
ebrad
2008-May-01 18:57 UTC
Re: Why doesn''t my user-entered data persist after validation/preview in my multi-model form?
Hi Roger, I''m wondering if you mean create a new a @timesheet_day (a.k.a Build)? If so, maybe that is my problem. This is a visualization of my model relationships: -Timesheet (main object where weekly totals are stored) ---TimesheetDay (for sun) ---TimesheetDay (for mon) ---TimesheetDay (for tues) ---TimesheetDay (for wed) ---TimesheetDay (for thurs) ---TimesheetDay (for fri) ---TimesheetDay (for sat) On Apr 30, 6:01 pm, "Roger Pack" <rogerpack2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> make sure you''re creating an @timesheet each time > > On Wed, Apr 30, 2008 at 2:06 PM, ebrad <nisguy_...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote: > > > 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!! > > > ### VIEW - Timesheet Form ####### > > > <h1>New timesheet</h1> > > > <% form_tag :action => ''create'' do %> > > > <% if params[:calculate] %> > > <div id="calculated" style="border: 1px solid #ddd; padding: 5px; > > background: #f8f8f8;"> > > <p><%= @timesheet.total_week_hours %></p> > > <%= submit_tag "Save and Finish" %> > > </div> > > <% end %> > > <%= error_messages_for ''timesheet'' %> > > > <p><label for="timesheet_week">Week: </label> > > <%= select ''timesheet'', ''week'', [ > > ["Beginning #{@last_week.to_s(:long)} (Last Week)", @last_week], > > ["Beginning #{@this_week.to_s(:long)} (This Week)", @this_week] > > ] %></p> > > > <table class="timesheet data_fields"> > > <tr> > > <th>Day</th> > > <th>Time In</th> > > <th>Time Out</th> > > <th></th> > > <th>Time In</th> > > <th>Time Out</th> > > <th></th> > > <th>PTO</th> > > <th>Vacation</th> > > <th>Holiday</th> > > <th>Jury</th> > > <th>Bereav.</th> > > <th>Ext PTO</th> > > <th>Unpaid</th> > > <th></th> > > <th>Comments</th> > > </tr> > > <% 7.times do |d| %> > > <tr class="<%= cycle(''odd'', ''even'') %>"> > > <%= render :partial => ''days'', :locals => { :day => d += 1 } %> > > </tr> > > <% end %> > > </table> > > > <%= submit_tag "Calculate", :name => ''calculate'' %> > > <% end %> > > > ## CONTROLLER - Timesheet ###### > > > ... > > def create > > week_select > > @timesheet = Timesheet.new(params[:timesheet]) > > if params[:calculate] > > run_calculations > > render :action => ''new'' > > elsif !...@timesheet.save > > render :action => ''new'' > > elsif @timesheet.save > > # some stuff... > > end > > ... > > end--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Roger Pack
2008-May-01 20:31 UTC
Re: Why doesn''t my user-entered data persist after validation/preview in my multi-model form?
maek sure your day rendering partial is using the right days [?] <tr class="<%= cycle(''odd'', ''even'') %>"> <%= render :partial => ''days'', :locals => { :day => d += 1 } %> </tr> On Thu, May 1, 2008 at 12:57 PM, ebrad <nisguy_300-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> > Hi Roger, > I''m wondering if you mean create a new a @timesheet_day (a.k.a Build)? > If so, maybe that is my problem. > > This is a visualization of my model relationships: > > -Timesheet (main object where weekly totals are stored) > ---TimesheetDay (for sun) > ---TimesheetDay (for mon) > ---TimesheetDay (for tues) > ---TimesheetDay (for wed) > ---TimesheetDay (for thurs) > ---TimesheetDay (for fri) > ---TimesheetDay (for sat) > > > > On Apr 30, 6:01 pm, "Roger Pack" <rogerpack2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > make sure you''re creating an @timesheet each time > > > > > > On Wed, Apr 30, 2008 at 2:06 PM, ebrad <nisguy_...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote: > > > > > 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!! > > > > > ### VIEW - Timesheet Form ####### > > > > > <h1>New timesheet</h1> > > > > > <% form_tag :action => ''create'' do %> > > > > > <% if params[:calculate] %> > > > <div id="calculated" style="border: 1px solid #ddd; padding: 5px; > > > background: #f8f8f8;"> > > > <p><%= @timesheet.total_week_hours %></p> > > > <%= submit_tag "Save and Finish" %> > > > </div> > > > <% end %> > > > <%= error_messages_for ''timesheet'' %> > > > > > <p><label for="timesheet_week">Week: </label> > > > <%= select ''timesheet'', ''week'', [ > > > ["Beginning #{@last_week.to_s(:long)} (Last Week)", @last_week], > > > ["Beginning #{@this_week.to_s(:long)} (This Week)", @this_week] > > > ] %></p> > > > > > <table class="timesheet data_fields"> > > > <tr> > > > <th>Day</th> > > > <th>Time In</th> > > > <th>Time Out</th> > > > <th></th> > > > <th>Time In</th> > > > <th>Time Out</th> > > > <th></th> > > > <th>PTO</th> > > > <th>Vacation</th> > > > <th>Holiday</th> > > > <th>Jury</th> > > > <th>Bereav.</th> > > > <th>Ext PTO</th> > > > <th>Unpaid</th> > > > <th></th> > > > <th>Comments</th> > > > </tr> > > > <% 7.times do |d| %> > > > <tr class="<%= cycle(''odd'', ''even'') %>"> > > > <%= render :partial => ''days'', :locals => { :day => d += 1 } %> > > > </tr> > > > <% end %> > > > </table> > > > > > <%= submit_tag "Calculate", :name => ''calculate'' %> > > > <% end %> > > > > > ## CONTROLLER - Timesheet ###### > > > > > ... > > > def create > > > week_select > > > @timesheet = Timesheet.new(params[:timesheet]) > > > if params[:calculate] > > > run_calculations > > > render :action => ''new'' > > > elsif !...@timesheet.save > > > render :action => ''new'' > > > elsif @timesheet.save > > > # some stuff... > > > end > > > ... > > > end > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
ebrad
2008-May-10 08:37 UTC
Re: Why doesn''t my user-entered data persist after validation/preview in my multi-model form?
k the problem was with the default values...they werer overriding the entered data upon re-rendering. I removed the defaults and it works. On May 1, 2:52 pm, ebrad <nisguy_...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> Yes, Ruby Freak, 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. > > On Apr 30, 6:54 pm, Ruby Freak <twscann...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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 !...@timesheet.save > > render :action => ''new'' > > elsif @timesheet.save > > # some stuff... > > end > > > On Apr 30, 3:01 pm, "Roger Pack" <rogerpack2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > make sure you''re creating an @timesheet each time > > > > On Wed, Apr 30, 2008 at 2:06 PM, ebrad <nisguy_...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote: > > > > > 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!! > > > > > ### VIEW - Timesheet Form ####### > > > > > <h1>New timesheet</h1> > > > > > <% form_tag :action => ''create'' do %> > > > > > <% if params[:calculate] %> > > > > <div id="calculated" style="border: 1px solid #ddd; padding: 5px; > > > > background: #f8f8f8;"> > > > > <p><%= @timesheet.total_week_hours %></p> > > > > <%= submit_tag "Save and Finish" %> > > > > </div> > > > > <% end %> > > > > <%= error_messages_for ''timesheet'' %> > > > > > <p><label for="timesheet_week">Week: </label> > > > > <%= select ''timesheet'', ''week'', [ > > > > ["Beginning #{@last_week.to_s(:long)} (Last Week)", @last_week], > > > > ["Beginning #{@this_week.to_s(:long)} (This Week)", @this_week] > > > > ] %></p> > > > > > <table class="timesheet data_fields"> > > > > <tr> > > > > <th>Day</th> > > > > <th>Time In</th> > > > > <th>Time Out</th> > > > > <th></th> > > > > <th>Time In</th> > > > > <th>Time Out</th> > > > > <th></th> > > > > <th>PTO</th> > > > > <th>Vacation</th> > > > > <th>Holiday</th> > > > > <th>Jury</th> > > > > <th>Bereav.</th> > > > > <th>Ext PTO</th> > > > > <th>Unpaid</th> > > > > <th></th> > > > > <th>Comments</th> > > > > </tr> > > > > <% 7.times do |d| %> > > > > <tr class="<%= cycle(''odd'', ''even'') %>"> > > > > <%= render :partial => ''days'', :locals => { :day => d += 1 } %> > > > > </tr> > > > > <% end %> > > > > </table> > > > > > <%= submit_tag "Calculate", :name => ''calculate'' %> > > > > <% end %> > > > > > ## CONTROLLER - Timesheet ###### > > > > > ... > > > > def create > > > > week_select > > > > @timesheet = Timesheet.new(params[:timesheet]) > > > > if params[:calculate] > > > > run_calculations > > > > render :action => ''new'' > > > > elsif !...@timesheet.save > > > > render :action => ''new'' > > > > elsif @timesheet.save > > > > # some stuff... > > > > end > > > > ... > > > > end--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---