Godless Infidel
2005-Apr-27 22:45 UTC
noob question: rhtml new/edit views and the date functionality
Hello All,
I''ve been playing with Rails - did the recipe/category sample from
onLamp.com - fairly straight forward - even got it working against
postgres.
Anyway, I''ve been appling rails to a small test project and I
can''t
seem to get the syntax down or find a sample of how to use the date
control on a custom new/edit view. The CRUD (is that right?) that
automatically detected the date field & generated the date dropdowns
when I didn''t specify any custom method overrides or custom views -
that was handy, but now I''m trying to generate a custom form to add
some style.
If anyone could please help me get the syntax down for the simple
recipe.date example to generate the date select boxes, I would be very
appreciative - I can then apply it to my test project.
Basically, the "Recipe" table looks like this:
id int8
title varchar(255)
description text
date timestamp
category_id int8 (fk to the category table)
and I need to generate the select boxes for the date column. I''ve
been browsing the API and the datetime_select/select_datetime and can
get the unbound stuff to show with this chunk of code:
<% =select_datetime(datetime = Time.now, options={}) %>
but I want it tied automagically to my database field. I know it is
something simple that i''ve overlooked and can''t seem to grasp
while
browsing the API. i''ve tried this which does not work:
<% = datetime_select(@recipe.date, "recipe[date]", options={}%>
The CRUD generates HTML like this:
year: <select name="recipe[date(1i)]">
month: <select name="recipe[date(2i)]">
...
seconds: <select name="recipe[date(6i)]">
which is essentially what I want.
Thank you,
Clay
Lord Khaos
2005-Apr-27 23:53 UTC
Re: noob question: rhtml new/edit views and the date functionality
On Wed, 2005-04-27 at 16:45 -0600, Godless Infidel wrote:> Hello All, > > I''ve been playing with Rails - did the recipe/category sample from > onLamp.com - fairly straight forward - even got it working against > postgres. > > Anyway, I''ve been appling rails to a small test project and I can''t > seem to get the syntax down or find a sample of how to use the date > control on a custom new/edit view.> I need to generate the select boxes for the date column. I''ve > been browsing the API and the datetime_select/select_datetime and can > get the unbound stuff to show with this chunk of code: > > <% =select_datetime(datetime = Time.now, options={}) %> > > but I want it tied automagically to my database field. I know it is > something simple that i''ve overlooked and can''t seem to grasp while > browsing the API. > > Thank you, > > ClayClay, If you haven''t already seen it, I think the Rails 4 Days tutorial has examples pretty close to what it is you''re wanting to do: http://www.rails4days.pwp.blueyonder.co.uk/Rails4Days.pdf HTH, Howard
Jarkko Laine
2005-Apr-28 05:53 UTC
Re: noob question: rhtml new/edit views and the date functionality
Clay. On 28.4.2005, at 01:45, Godless Infidel wrote:> but I want it tied automagically to my database field. I know it is > something simple that i''ve overlooked and can''t seem to grasp while > browsing the API. i''ve tried this which does not work: > > <% = datetime_select(@recipe.date, "recipe[date]", options={}%>Form helpers generally take their parameters as (object, method, {hash_of_other_options} ). There is exceptions, of course, so consult the api docs (http://rails.rubyonrails.com) for the exact syntax. datetime_select is no exception, so you should call it like this: <%= datetime_select("recipe", "date") %> If you don''t have any options, don''t specify them. ={} in the function definition means that an empty hash is the default options parameter unless something else has been given. API docs have often examples (like in this case http://rails.rubyonrails.com/classes/ActionView/Helpers/ DateHelper.html#M000382) which you can draw advantage from if you''re not quite sure how you should use the function.> > The CRUD generates HTML like this: > year: <select name="recipe[date(1i)]"> > month: <select name="recipe[date(2i)]"> > ... > seconds: <select name="recipe[date(6i)]"> > > which is essentially what I want.No, scaffold doesn''t generate that, it generates a datetime_select call (see the rhtml file for the action in question). When that function is called, it expands to the html input fields you describe above. //jarkko> > Thank you, > > Clay > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails