I'm trying to insert a record containing a birthdate with
activescaffold. However, the year-dropdown box is only showing years
starting from 2002. This means that people over 5 years old cannot use
the application which, unfortunately, does not meet the functional
requirements. (Would save lots of difficult questions though!)
How can I set the starting year? With standard rails it is set like
this:
date_select :geboortedatum, :order =>
[:day, :month, :year], :start_year => 1970, :end_year => 2000
The funny thing is that in 'edit mode', the years start at 1969 but in
'new' mode it starts at 2002.
Thanks in advance,
Ger Apeldoorn
---------------leerling_helper.rb---------------
module Admin::LeerlingHelper
def geboortedatum_form_column(record, input_name)
select_date record[:geboortedatum], :name =>
'geboortedatum', :order => [:day, :month, :year], :start_year =>
1970, :end_year => 2000
end
end
---------------/leerling_helper.rb---------------
The override is beiing used (order changed), but the values are not
beiing stored to the database.
I think it is because of the select's name. Here is an excerpt of the
html-source that is generated:
---------------%<---------------
<label for="record_geboortedatum">Geboortedatum</label>
<select id="date_day" name="date[day]">
<option value="1">1</option>
<option value="2">2</option>
---------------%<---------------
Shouldn-t that be name="geboortedatum[day]"?
how can I change it?
Many thanks,
Ger.
select_date record[:geboortedatum], :prefix =>
'record_geboortedatum', :order => [:day, :month, :year], :start_year
=> 1970, :end_year => 2000
This makes the code for the select like this (note the name field):
---------------%<---------------
<select id="record_geboortedatum_day"
name="record_geboortedatum[day]">
---------------%<---------------
Without the override in the helper (which does save the values in the
DB):
---------------%<---------------
<select id="record_geboortedatum_1i" name="record[geboortedatum(1i)]">
---------------%<---------------
My code gives the value in a hash (record_geboortedatum[day]). It
SHOULD give the value back in a hash(?) which is itself in the record
hash. (record[geboortedatum(1i)])
How can I achieve this little miracle???
Greetings & Salutations,
Ger.
On 17 apr, 09:30, Vorik <goo...@gerapeldoorn.nl> wrote:
> Thanks for the tip Lance, but I'm not there yet.... This is what I've
> come up with:
>
> ---------------leerling_helper.rb---------------
> module Admin::LeerlingHelper
> def geboortedatum_form_column(record, input_name)
> select_daterecord[:geboortedatum], :name =>
Unfortunately, your example gives an error(ActionView::TemplateError
(undefined method `day' for :record:Symbol)). I've changed :record to
record[:geboortedatum].
select_date record[:geboortedatum], :name => input_name, :order =>
[:day, :month, :year], :start_year => 1970, :end_year => 2000
does not store the values in the database.....
This is the HTML source:
<label for="record_geboortedatum">Geboortedatum</label>
<select id="date_day" name="date[day]">
<option value="1">1</option>
Your help is very much appreciated!!
Thanks,
Ger.
This is still a problem for me, any insights (or pointers to some
working code) are very much appreciated!!
Thanks,
Ger.
In the Helper I added
module AssetsHelper
def date_received_form_column(record, input_name)
select_date record[:date_received],:name=>input_name, :include_blank
=> true
end
To create a "null" on the drop down... The null now appears in tho
HTML, and the data is reformatted correctly. But, the date is never
updated in the database (for Nulls or any data changes)
.
The log has no errors, but the trace record is below ... Note that I
do have numerous dates, the only one overriden is "Date_recieved" ...
It was set to 4/2/2000 .. But alas, no update to the database.
Note that the trace shows date"=>{"month"=>"4", "day"=>"2",
"year"=>"2000"}, seems to refer to the "date_received" which I set to
4/2/2000 ..
Processing AssetsController#update (for 127.0.0.1 at 2007-04-24
08:41:10) [PUT]
Session ID: 312a7c8f9387cb3ba443304768084054
Parameters: {"commit"=>"Update", "date"=>{"month"=>"4", "day"=>"2",
"year"=>"2000"}, "_method"=>"put", "action"=>"update", "id"=>"7",
"controller"=>"assets", "associated_id"=>"",
"record"=>{"name"=>"0004569", "date_excessed(5i)"=>"00",
"orig_cost"=>"0",
"issuances"=>{"1177418430937"=>{"date_installed(5i)"=>"40",
"Orig_Issuance"=>"", "patch_method"=>{"id"=>""},
"date_removed(1i)"=>"2007", "date_removed(2i)"=>"4",
"date_installed(1i)"=>"2007", "use"=>{"id"=>""},
"date_removed(3i)"=>"24", "customer"=>{"id"=>""},
"date_installed(2i)"=>"4", "named_server"=>{"id"=>""},
"date_installed(3i)"=>"24", "date_removed(4i)"=>"08",
"room"=>{"id"=>""}, "lan_desk"=>"false", "date_installed(4i)"=>"08",
"holding_account"=>{"id"=>""}, "date_removed(5i)"=>"40"},
"4707"=>{"date_installed(5i)"=>"26", "Orig_Issuance"=>"",
"id"=>"4707", "patch_method"=>{"id"=>""}, "date_removed(1i)"=>"2007",
"date_removed(2i)"=>"4", "date_installed(1i)"=>"2007",
"use"=>{"id"=>""}, "customer"=>{"id"=>""}, "date_removed(3i)"=>"24",
"date_installed(2i)"=>"4", "room"=>{"id"=>""}, "lan_desk"=>"false",
"named_server"=>{"id"=>""}, "date_removed(4i)"=>"08",
"date_installed(3i)"=>"24", "date_installed(4i)"=>"08",
"holding_account"=>{"id"=>""}, "date_removed(5i)"=>"26"},
"4708"=>{"date_installed(5i)"=>"30", "Orig_Issuance"=>"",
"id"=>"4708", "patch_method"=>{"id"=>""}, "date_removed(1i)"=>"2007",
"date_removed(2i)"=>"4", "date_installed(1i)"=>"2007",
"use"=>{"id"=>""}, "date_removed(3i)"=>"24", "customer"=>{"id"=>""},
"date_installed(2i)"=>"4", "named_server"=>{"id"=>""},
"room"=>{"id"=>""}, "date_removed(4i)"=>"08",
"date_installed(3i)"=>"24", "lan_desk"=>"false",
"holding_account"=>{"id"=>""}, "date_removed(5i)"=>"30",
"date_installed(4i)"=>"08"}}, "date_last_inventory(1i)"=>"2007",
"date_last_inventory(2i)"=>"4", "date_last_inventory(3i)"=>"24",
"date_last_inventory(4i)"=>"08", "tagged"=>"false",
"date_last_inventory(5i)"=>"26", "date_excessed(1i)"=>"2003",
"orig_po"=>"dr = 2000\\4\\2", "date_excessed(2i)"=>"4",
"date_excessed(3i)"=>"1", "xmodel"=>{"name"=>"HP LaserJet Series II",
"brand"=>{"id"=>"26"}, "category"=>{"id"=>"6"},
"model_specs"=>{"514"=>{"id"=>"430"}}, "id"=>"300",
"standard"=>{"id"=>"40"}, "part_number"=>"33440A"},
"date_excessed(4i)"=>"00"}}
Rendering /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/
action_controller/templates/rescues/layout.rhtml (500 Internal Error)
---------------%<---------------
action_controller/benchmarking.rb:26:in `benchmark'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
partials.rb:58:in `render_partial_without_active_scaffold'
#{RAILS_ROOT}/vendor/plugins/active_scaffold/lib/extensions/
action_view.rb:55:in `render_partial'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
base.rb:287:in `render_without_active_scaffold'
#{RAILS_ROOT}/vendor/plugins/active_scaffold/lib/extensions/
action_view.rb:45:in `render'
#{RAILS_ROOT}/vendor/plugins/active_scaffold/frontends/default/
views/_form.rhtml:6:in
`_run_rhtml_47vendor47plugins47active_scaffold47frontends47default47views47_form46rhtml'
#{RAILS_ROOT}/vendor/plugins/active_scaffold/lib/data_structures/
action_columns.rb:65:in `each'
#{RAILS_ROOT}/vendor/plugins/active_scaffold/lib/data_structures/
action_columns.rb:52:in `each'
#{RAILS_ROOT}/vendor/plugins/active_scaffold/frontends/default/
views/_form.rhtml:2:in
`_run_rhtml_47vendor47plugins47active_scaffold47frontends47default47views47_form46rhtml'
/usr/lib/ruby/gems/1.8/gems/actionpack- 1.13.2/lib/action_view/
base.rb:326:in `compile_and_render_template'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
base.rb:301:in `render_template'
/usr/lib/ruby/gems/1.8/gems/actionpack- 1.13.2/lib/action_view/
base.rb:260:in `render_file'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
base.rb:275:in `render_without_active_scaffold'
#{RAILS_ROOT}/vendor/plugins/active_scaffold/lib/extensions/
action_view.rb:45:in `render'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
partials.rb:59:in `render_partial_without_active_scaffold'
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2 /lib/
action_controller/benchmarking.rb:26:in `benchmark'
/usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
/usr/lib/ruby/1.8/benchmark.rb:307:in `realtime'
/usr/lib/ruby/gems/1.8/gems/actionpack- 1.13.2/lib/
/usr/lib/ruby/gems/1.8/gems/mongrel- 1.0.1/lib/mongrel.rb:618:in
Thanks for your reply. I did check the Rails API for the select_date
method.
Can you be a bit more specific about what I'm doing wrong here?
Note that in post 6 I've changed your example to something that didn't
give an error but did not store the value in the database either.
Thanks again,
Ger.
> > views/_form.rhtml:6:in
>
> > `_run_rhtml_47vendor47plugins47active_scaffold47frontends47default47views47_form46rhtml'
> > #{RAILS_ROOT}/vendor/plugins/active_scaffold/lib/data_structures/
> > action_columns.rb:65:in `each'
> > #{RAILS_ROOT}/vendor/plugins/active_scaffold/lib/data_structures/
> > action_columns.rb:52:in `each'
> > #{RAILS_ROOT}/vendor/plugins/active_scaffold/frontends/default/
> > views/_form.rhtml:2:in
>
> > `_run_rhtml_47vendor47plugins47active_scaffold47frontends47default47views47_form46rhtml'
> > #{RAILS_ROOT}/vendor/plugins/active_scaffold/lib/extensions/
> > action_controller.rb:13:in `render'
> > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/
> > action_controller/base.rb:786:in `render_to_string'
> > /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/
> > deprecation.rb:43:in `silence'
> > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/
> > action_controller/base.rb:786:in `render_to_string'
> > #{RAILS_ROOT}/vendor/plugins/active_scaffold/lib/extensions/
> > action_controller.rb:9:in `render'
> > #{RAILS_ROOT}/vendor/plugins/active_scaffold/lib/actions/update.rb:
> > 22:in `edit'
>
> ...
>
> read more »
> > base.rb:287:in `render_without_active_scaffold'
> > #{RAILS_ROOT}/vendor/plugins/active_scaffold/lib/extensions/
> > action_view.rb:45:in `render'
> > #{RAILS_ROOT}/vendor/plugins/active_scaffold/frontends/default/
> > views/_form.rhtml:6:in
>
> > `_run_rhtml_47vendor47plugins47active_scaffold47frontends47default47views47_form46rhtml'
> > #{RAILS_ROOT}/vendor/plugins/active_scaffold/lib/data_structures/
> > action_columns.rb:65:in `each'
> > #{RAILS_ROOT}/vendor/plugins/active_scaffold/lib/data_structures/
> > action_columns.rb:52:in `each'
> > #{RAILS_ROOT}/vendor/plugins/active_scaffold/frontends/default/
> > views/_form.rhtml:2:in
>
> > `_run_rhtml_47vendor47plugins47active_scaffold47frontends47default47views47_form46rhtml'
> > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
> > base.rb:326:in `compile_and_render_template'
> > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
> > base.rb:301:in `render_template'
> > /usr/lib/ruby/gems/1.8/gems/actionpack- 1.13.2/lib/action_view/
> > base.rb:260:in `render_file'
> > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
> > base.rb:275:in `render_without_active_scaffold'
> > #{RAILS_ROOT}/vendor/plugins/active_scaffold/lib/extensions/
> > action_view.rb:45:in `render'
> > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
> > partials.rb:59:in `render_partial_without_active_scaffold'
> > /usr/lib/ruby/gems/1.8/gems/actionpack- 1.13.2/lib/
> > action_controller/benchmarking.rb:26:in `benchmark'
> > /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
> > /usr/lib/ruby/1.8/benchmark.rb:307:in `realtime'
> > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/
> > action_controller/benchmarking.rb:26:in `benchmark'
> > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
> > partials.rb:58:in `render_partial_without_active_scaffold'
> > #{RAILS_ROOT}/vendor/plugins/active_scaffold/lib/extensions/
> > action_view.rb:55:in `render_partial'
> > /usr/lib/ruby/gems/1.8/gems/actionpack- 1.13.2/lib/action_view/
> > base.rb:287:in `render_without_active_scaffold'
> > #{RAILS_ROOT}/vendor/plugins/active_scaffold/lib/extensions/
> > action_view.rb:45:in `render'
> > #{RAILS_ROOT}/vendor/plugins/active_scaffold/frontends/default/
> > views/_update_form.rhtml:29:in
>
> > `_run_rhtml_47vendor47plugins47active_scaffold47frontends47default47views47_update_form46rhtml'
> > /usr/lib/ruby/gems/1.8/gems/actionpack- 1.13.2/lib/action_view/
> > base.rb:326:in `compile_and_render_template'
> > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
> > base.rb:301:in `render_template'
> > /usr/lib/ruby/gems/1.8/gems/actionpack- 1.13.2/lib/action_view/
> > base.rb:260:in `render_file'
> > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
> > base.rb:275:in `render_without_active_scaffold'
> > #{RAILS_ROOT}/vendor/plugins/active_scaffold/lib/extensions/
> > action_view.rb:45:in `render'
> > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
> > partials.rb:59:in `render_partial_without_active_scaffold'
> > /usr/lib/ruby/gems/1.8/gems/actionpack- 1.13.2/lib/
> > action_controller/benchmarking.rb:26:in `benchmark'
> > /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
> > /usr/lib/ruby/1.8/benchmark.rb:307:in `realtime'
> > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/
> > action_controller/benchmarking.rb:26:in `benchmark'
> > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
> > partials.rb:58:in `render_partial_without_active_scaffold'
> > #{RAILS_ROOT}/vendor/plugins/active_scaffold/lib/extensions/
> > action_view.rb:55:in `render_partial'
> > /usr/lib/ruby/gems/1.8/gems/actionpack- 1.13.2/lib/
> read more �
I've found my solution using date_select. Strangely, it takes the hash
as the first element, then the key as the second. (or am i reading
this all wrong?)
Anyway, now it works fine, thanks for your help!
For future reference:
put this in the relevant helper, 'geboortedatum' is the field name
(Dutch for birthdate) and the controller is Admin::LeerlingController.
----%<-----
module Admin::LeerlingHelper
def geboortedatum_form_column(record, input_name)
date_select(:record, :geboortedatum, :order =>
[:day, :month, :year], :start_year => 1970, :end_year => 2000)
end
end
----%<-----
> > > > base.rb:260:in `render_file'
> > > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
> > > > base.rb:275:in `render_without_active_scaffold'
> > > > #{RAILS_ROOT}/vendor/plugins/active_scaffold/lib/extensions/
> > > > action_view.rb:45:in `render'
> > > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
> > > > partials.rb:59:in `render_partial_without_active_scaffold'
> > > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/
> > > > action_controller/benchmarking.rb:26:in `benchmark'
> > > > /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
> > > > /usr/lib/ruby/1.8/benchmark.rb:307:in `realtime'
> > > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/
> > > > action_controller/benchmarking.rb:26:in `benchmark'
> > > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
> > > > partials.rb:58:in `render_partial_without_active_scaffold'
> > > > #{RAILS_ROOT}/vendor/plugins/active_scaffold/lib/extensions/
> > > > action_view.rb:55:in `render_partial'
> > > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
> > > > base.rb:287:in `render_without_active_scaffold'
> > > > #{RAILS_ROOT}/vendor/plugins/active_scaffold/lib/extensions/
> > > > action_view.rb:45:in `render'
> > > > #{RAILS_ROOT}/vendor/plugins/active_scaffold/frontends/default/
> > > > views/_form.rhtml:6:in
>
> > `_run_rhtml_47vendor47plugins47active_scaffold47frontends47default47views47_form46rhtml'
> > > > #{RAILS_ROOT}/vendor/plugins/active_scaffold/lib/data_structures/
> > > > action_columns.rb:65:in `each'
> > > > #{RAILS_ROOT}/vendor/plugins/active_scaffold/lib/data_structures/
> > > > action_columns.rb:52:in `each'
> > > > #{RAILS_ROOT}/vendor/plugins/active_scaffold/frontends/default/
> > > > views/_form.rhtml:2:in
>
> > `_run_rhtml_47vendor47plugins47active_scaffold47frontends47default47views47_form46rhtml'
> > > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
> > > > base.rb:326:in `compile_and_render_template'
> > > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
> > > > base.rb:301:in `render_template'
> > > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
> > > > base.rb:260:in `render_file'
> > > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
> > > > base.rb:275:in `render_without_active_scaffold'
> > > > #{RAILS_ROOT}/vendor/plugins/active_scaffold/lib/extensions/
> > > > action_view.rb:45:in `render'
> > > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
> > > > partials.rb:59:in `render_partial_without_active_scaffold'
> > > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/
> > > > action_controller/benchmarking.rb:26:in `benchmark'
> > > > /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
> > > > /usr/lib/ruby/1.8/benchmark.rb:307:in `realtime'
> > > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/
> > > > action_controller/benchmarking.rb:26:in `benchmark'
> > > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
> > > > partials.rb:58:in `render_partial_without_active_scaffold'
> > > > #{RAILS_ROOT}/vendor/plugins/active_scaffold/lib/extensions/
> > > > action_view.rb:55:in `render_partial'
> > > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
> > > > base.rb:287:in `render_without_active_scaffold'
> > > > #{RAILS_ROOT}/vendor/plugins/active_scaffold/lib/extensions/
> > > > action_view.rb:45:in `render'
> > > > #{RAILS_ROOT}/vendor/plugins/active_scaffold/frontends/default/
> > > > views/_update_form.rhtml:29:in
>
> > `_run_rhtml_47vendor47plugins47active_scaffold47frontends47default47views47_update_form46rhtml'
> > > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
> > > > base.rb:326:in `compile_and_render_template'
> > > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
> > > > base.rb:301:in `render_template'
> > > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
> > > > base.rb:260:in `render_file'
> > > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
> > > > base.rb:275:in `render_without_active_scaffold'
> > > > #{RAILS_ROOT}/vendor/plugins/active_scaffold/lib/extensions/
> > > > action_view.rb:45:in `render'
> > > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_view/
> > > > partials.rb:59:in `render_partial_without_active_scaffold'
> > > > /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/
> > > > action_controller/benchmarking.rb:26:in `benchmark'
> > > > /usr/lib/ruby/1.8/benchmark.rb:293:in
>
> ...
>
> read more »