Francesco Belladonna
2009-Oct-20 01:40 UTC
From 3 fields :date input from forms to 1 field
Hi Rails community, here is my newbie problem (I''m migrating from PHP to ruby due to framework and ruby syntax, but I''m having some problems with "freedom" that a single php page offers): I''m using the scaffolding technique (yea, I love it) to create a webpage, but if I specify that a field type is :date, Rails auto generate a form where the field of type :date is created through 3 fields: day, month and year. I would like to use only one field (always) (will be something that I''ll use for all :date field-type), a text field, where the date will be written in dd/mm/YY format, how can I do this without writing something in javascript that "set some hidden fields" (month and year) when you write in the text field? Are there a "general" way (as I''ve said, I''ll use this always instead of normal way of setting dates)? Thanks -- Posted via http://www.ruby-forum.com/.
On Tue, Oct 20, 2009 at 3:40 AM, Francesco Belladonna <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi Rails community, here is my newbie problem (I''m migrating from PHP to > ruby due to framework and ruby syntax, but I''m having some problems with > "freedom" that a single php page offers): > > I''m using the scaffolding technique (yea, I love it) to create a > webpage, but if I specify that a field type is :date, Rails auto > generate a form where the field of type :date is created through 3 > fields: day, month and year. > > I would like to use only one field (always) (will be something that I''ll > use for all :date field-type), a text field, where the date will be > written in dd/mm/YY format, how can I do this without writing something > in javascript that "set some hidden fields" (month and year) when you > write in the text field?How would you do that on PHP?> > Are there a "general" way (as I''ve said, I''ll use this always instead of > normal way of setting dates)?Scaffold will generate the form, but you can modify it as you please. Change the form and make sure the parameters are OK in the controller (yes, with tests) Hope it helps. -- Leonardo Mateo. There''s no place like ~
Francesco Belladonna
2009-Oct-20 11:17 UTC
Re: From 3 fields :date input from forms to 1 field
Leonardo Mateo wrote:> On Tue, Oct 20, 2009 at 3:40 AM, Francesco Belladonna > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> I would like to use only one field (always) (will be something that I''ll >> use for all :date field-type), a text field, where the date will be >> written in dd/mm/YY format, how can I do this without writing something >> in javascript that "set some hidden fields" (month and year) when you >> write in the text field? > How would you do that on PHP? > >> >> Are there a "general" way (as I''ve said, I''ll use this always instead of >> normal way of setting dates)? > > Scaffold will generate the form, but you can modify it as you please. > Change the form and make sure the parameters are OK in the controller > (yes, with tests) > > Hope it helps. > > -- > Leonardo Mateo. > There''s no place like ~In PHP I don''t have a predefined framework and so I don''t have rules to follow (but this is not a good thing: I''m changing from PHP to Ruby also for this reason), I have to write my own form and rewrite the way I use it for storing informations BTW, I''m quite sure that I''m not explaining very well but I''ve found something: In ActionView::Helpers::DateHelper there is "date_select" method, which creates html tags formatted in a way, so the day selection tag will have "name" attribute "calendar[mydate(3i)]", the month will have "calendar[mydate(2i)]" and so on. If I change these tags in my single text field tag I will have "calendar[mydate]" and nothing else, but when I send this information obviusly ruby should understand how to "split" this date to store it: where should I do this (and where could I read my submitted vars?)? In controller I only have Calendar.new(params[:calendar]) in create method, so I think that params should be "changed" in some way, is this the good way? -- Posted via http://www.ruby-forum.com/.
On Tue, Oct 20, 2009 at 8:17 AM, Francesco Belladonna <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Leonardo Mateo wrote: >> On Tue, Oct 20, 2009 at 3:40 AM, Francesco Belladonna >> <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >>> I would like to use only one field (always) (will be something that I''ll >>> use for all :date field-type), a text field, where the date will be >>> written in dd/mm/YY format, how can I do this without writing something >>> in javascript that "set some hidden fields" (month and year) when you >>> write in the text field? >> How would you do that on PHP? >> >>> >>> Are there a "general" way (as I''ve said, I''ll use this always instead of >>> normal way of setting dates)? >> >> Scaffold will generate the form, but you can modify it as you please. >> Change the form and make sure the parameters are OK in the controller >> (yes, with tests) >> >> Hope it helps. >> >> -- >> Leonardo Mateo. >> There''s no place like ~ > In PHP I don''t have a predefined framework and so I don''t have rules to > follow (but this is not a good thing: I''m changing from PHP to Ruby also > for this reason), I have to write my own form and rewrite the way I use > it for storing informations > > BTW, I''m quite sure that I''m not explaining very well but I''ve found > something: > In ActionView::Helpers::DateHelper there is "date_select" method, which > creates html tags formatted in a way, so the day selection tag will have > "name" attribute "calendar[mydate(3i)]", the month will have > "calendar[mydate(2i)]" and so on. If I change these tags in my single > text field tag I will have "calendar[mydate]" and nothing else, but when > I send this information obviusly ruby should understand how to "split" > this date to store it: where should I do this (and where could I read my > submitted vars?)? In controller I only have > Calendar.new(params[:calendar]) in create method, so I think that params > should be "changed" in some way, is this the good way?Yes, I don''t think there''s any other way to do that. You should parse your params[:calendar][:mydateXX] and format them in the way you need. I would do something like: day = params[:calendar] .delete("mydate(3i)") month = params[:calendar] .delete("mydate(3i)") year = params[:calendar] .delete("mydate(3i)") #I don''t really remember the order they are stored, but you get the idea Then, do somehting like: params[:calendar][:name_of_the_date_field_here] = Date.new(year, month, day) And then: Calendar.new(params[:calendar] But that''s just my first approach to this, maybe you can figure out a better way to do it. Hope it helps. -- Leonardo Mateo. There''s no place like ~
I found this helpful: http://railscasts.com/episodes/73-complex-forms-part-1 and the two episodes that follow. On Oct 20, 12:55 pm, Leonardo Mateo <leonardoma...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Tue, Oct 20, 2009 at 8:17 AM, Francesco Belladonna > > > > <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > Leonardo Mateo wrote: > >> On Tue, Oct 20, 2009 at 3:40 AM, Francesco Belladonna > >> <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > >>> I would like to use only one field (always) (will be something that I''ll > >>> use for all :date field-type), a text field, where the date will be > >>> written in dd/mm/YY format, how can I do this without writing something > >>> in javascript that "set some hidden fields" (month and year) when you > >>> write in the text field? > >> How would you do that on PHP? > > >>> Are there a "general" way (as I''ve said, I''ll use this always instead of > >>> normal way of setting dates)? > > >> Scaffold will generate the form, but you can modify it as you please. > >> Change the form and make sure the parameters are OK in the controller > >> (yes, with tests) > > >> Hope it helps. > > >> -- > >> Leonardo Mateo. > >> There''s no place like ~ > > In PHP I don''t have a predefined framework and so I don''t have rules to > > follow (but this is not a good thing: I''m changing from PHP to Ruby also > > for this reason), I have to write my own form and rewrite the way I use > > it for storing informations > > > BTW, I''m quite sure that I''m not explaining very well but I''ve found > > something: > > In ActionView::Helpers::DateHelper there is "date_select" method, which > > creates html tags formatted in a way, so the day selection tag will have > > "name" attribute "calendar[mydate(3i)]", the month will have > > "calendar[mydate(2i)]" and so on. If I change these tags in my single > > text field tag I will have "calendar[mydate]" and nothing else, but when > > I send this information obviusly ruby should understand how to "split" > > this date to store it: where should I do this (and where could I read my > > submitted vars?)? In controller I only have > > Calendar.new(params[:calendar]) in create method, so I think that params > > should be "changed" in some way, is this the good way? > > Yes, I don''t think there''s any other way to do that. You should parse > your params[:calendar][:mydateXX] and format them in the way you need. > I would do something like: > day = params[:calendar] .delete("mydate(3i)") > month = params[:calendar] .delete("mydate(3i)") > year = params[:calendar] .delete("mydate(3i)") > #I don''t really remember the order they are stored, but you get the idea > Then, do somehting like: > params[:calendar][:name_of_the_date_field_here] = Date.new(year, month, day) > And then: > Calendar.new(params[:calendar] > > But that''s just my first approach to this, maybe you can figure out a > better way to do it. > > Hope it helps. > > -- > Leonardo Mateo. > There''s no place like ~
Francesco Belladonna
2009-Oct-20 20:27 UTC
Re: From 3 fields :date input from forms to 1 field
Leonardo Mateo wrote:> On Tue, Oct 20, 2009 at 8:17 AM, Francesco Belladonna > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >>> >>> -- >> creates html tags formatted in a way, so the day selection tag will have >> "name" attribute "calendar[mydate(3i)]", the month will have >> "calendar[mydate(2i)]" and so on. If I change these tags in my single >> text field tag I will have "calendar[mydate]" and nothing else, but when >> I send this information obviusly ruby should understand how to "split" >> this date to store it: where should I do this (and where could I read my >> submitted vars?)? In controller I only have >> Calendar.new(params[:calendar]) in create method, so I think that params >> should be "changed" in some way, is this the good way? > > Yes, I don''t think there''s any other way to do that. You should parse > your params[:calendar][:mydateXX] and format them in the way you need. > I would do something like: > day = params[:calendar] .delete("mydate(3i)") > month = params[:calendar] .delete("mydate(3i)") > year = params[:calendar] .delete("mydate(3i)") > #I don''t really remember the order they are stored, but you get the idea > Then, do somehting like: > params[:calendar][:name_of_the_date_field_here] = Date.new(year, month, > day) > And then: > Calendar.new(params[:calendar] > > But that''s just my first approach to this, maybe you can figure out a > better way to do it. > > Hope it helps. > > > -- > Leonardo Mateo. > There''s no place like ~Thanks your suggestion actually is working for me (and better: I''ve understood it) theambler wrote:> I found this helpful: > > http://railscasts.com/episodes/73-complex-forms-part-1 > > and the two episodes that follow.These seems even better, but actually I have some difficults in understanding it (I''m at the very beginning, so I''m having troubles in understanding some processes) -- Posted via http://www.ruby-forum.com/.
2009/10/20 Francesco Belladonna <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > Leonardo Mateo wrote: >> On Tue, Oct 20, 2009 at 8:17 AM, Francesco Belladonna >> <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >>>> >>>> -- >>> creates html tags formatted in a way, so the day selection tag will have >>> "name" attribute "calendar[mydate(3i)]", the month will have >>> "calendar[mydate(2i)]" and so on. If I change these tags in my single >>> text field tag I will have "calendar[mydate]" and nothing else, but when >>> I send this information obviusly ruby should understand how to "split" >>> this date to store it: where should I do this (and where could I read my >>> submitted vars?)? In controller I only have >>> Calendar.new(params[:calendar]) in create method, so I think that params >>> should be "changed" in some way, is this the good way? >> >> Yes, I don''t think there''s any other way to do that. You should parse >> your params[:calendar][:mydateXX] and format them in the way you need. >> I would do something like: >> day = params[:calendar] .delete("mydate(3i)") >> month = params[:calendar] .delete("mydate(3i)") >> year = params[:calendar] .delete("mydate(3i)") >> #I don''t really remember the order they are stored, but you get the idea >> Then, do somehting like: >> params[:calendar][:name_of_the_date_field_here] = Date.new(year, month, >> day) >> And then: >> Calendar.new(params[:calendar] >> >> But that''s just my first approach to this, maybe you can figure out a >> better way to do it. >> >> Hope it helps. >> >> >> -- >> Leonardo Mateo. >> There''s no place like ~ > > Thanks your suggestion actually is working for me (and better: I''ve > understood it) > > theambler wrote: >> I found this helpful: >> >> http://railscasts.com/episodes/73-complex-forms-part-1 >> >> and the two episodes that follow. > > These seems even better, but actually I have some difficults in > understanding it (I''m at the very beginning, so I''m having troubles in > understanding some processes)Just to check that you have also seen the rails guides at http://guides.rubyonrails.org/ The Getting Started, ActiveRecord Associations, Debugging, and Testing guides are compulsory reading (and re-reading and experimenting till it makes sense). Colin Colin
Francesco Belladonna
2009-Oct-20 20:57 UTC
Re: From 3 fields :date input from forms to 1 field
Colin Law wrote:> Just to check that you have also seen the rails guides at > http://guides.rubyonrails.org/ > The Getting Started, ActiveRecord Associations, Debugging, and Testing > guides are compulsory reading (and re-reading and experimenting till > it makes sense). > > Colin > > ColinThanks, I''ll read them as fast as possible -- Posted via http://www.ruby-forum.com/.