Form woes

I have a form which generates a report. The first issue I ran into was trying to create a model to validate some of the entries without saving them....that didnt' work out too well, so I created a report table. I figured uses could save reports for later viewing as a feature.

The form has two field names: report for fields pertaining to the report and :check which are fields not being saved. The check fields have names like: "use_agreed_to_participate" which let me know to use the data in that field to filter by. Here's a snippet:

<div class='reportRow' >

  <div class='reportLeftCell'>

   Schedule Date

  </div>

  <div class='reportCenterCell' id='reportScheduleSelects'>

    From:

    <%= datetime_select('report', 'schedule_date_to') %><br /><br />

    <%= datetime_select('report', 'schedule_date_from') %>

  </div>

  <div class='reportRightCell'>

    <%= check_box('check','use_schedule_date', :checked_value => "1", :unchecked_value => "0") %>   </div>

</div>

Everything works perfect unless my Report object throws an error on save which brings you back to the form page.

Error snippet:

Showing app/views/admin/_report_form.rhtml where line #31 raised:

undefined method `use_updated_on' for #<HashWithIndifferentAccess:0x3c3df2c>

Extracted source (around line #31):

28: <%= datetime_select('report', 'updated_on_to') %> 29: </div> 30: <div class='reportRightCell'> 31: <%= check_box('check','use_updated_on', :checked_value => "1", :unchecked_value => "0") %> 32: </div> 33: </div> 34:

The trace: /opt/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/helpers/form_helper.rb:333:in `send' /opt/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/helpers/form_helper.rb:333:in `value' /opt/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/helpers/form_helper.rb:281:in `to_check_box_tag' /opt/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/helpers/form_helper.rb:208:in `check_box' #{RAILS_ROOT}/app/views/admin/_report_form.rhtml:31:in `_run_rhtml_admin__report_form' #{RAILS_ROOT}/app/views/admin/report.rhtml:7:in `_run_rhtml_admin_report' #{RAILS_ROOT}/app/controllers/admin_controller.rb:39:in `new_report'

And finally, liine #39 in new_report:

35 @report = Report.new(@temp)

36 if @report.save

37 redirect_to :action => :show_report, :id => @report[:id]

38 else

39 render :action => 'report'

40 end

I know I'm probably missing something simple here and it has something to do with use_updated_on (and friends) not having a model backend..but is there an elegant way to fix this without hacking rails source or some such?

As usual, as soon as I take the time to submit to list I find the answer. So I'll answer it here:

Please look into attr_accessor setting for your model.

Krunk,

I am having the same problem, except with radio buttons, and I don't understand how you solved it with an attr_accessor. Could you explain a bit more in depth?

Thanks, Peter

Actually I also figured it out right after I sent the email... and truly all I needed was the attr_accessor... so thanks!