Hello I am having trouble with datetime objects, I had the "good" idea
of making a form, asking for the parameters of DateTime and then give
this object to the Database, apparently this is not the way.
I have this error: wrong number of arguments (2 for 1)
And this is what I tried:
I have a model like this
datetime :when
string :where
A view like this
<% form_tag exams_path do %>
<p>
Place:<br/>
<%= text_field_tag ''place'' %>
</p>
<p>
Date and Hour:<br/>
Day: <%= text_field_tag ''day'', nil, :size => 4,
:maxlength => 2
%><br/>
Month: <%= text_field_tag ''month'',nil, :size => 4,
:maxlength => 2
%><br/>
year: <%= text_field_tag ''year'', nil, :size => 4,
:maxlength => 4
%><br/>
Hour: <%= text_field_tag ''hour'', nil, :size => 4,
:maxlength => 2
%><br/>
Minute: <%=text_field_tag ''minute'',nil, :size => 4,
:maxlength =>
2%><br/>
</p>
<p>
<%= submit_tag ''Save'' %>
</p>
<% end %>
And a controller like this
@fecha = DateTime.new(params[:year].to_i, params[:month].to_i,
params[:day].to_i, params[:hour].to_i, params[:minute].to_i)
@exam = Exam.new(DateTime.now, params[:place])
if @exam.save
redirect_to exams_path
else
render :action => ''new''
end
Thanks for your help.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Sep-05 07:19 UTC
Re: Error trying to save DateTime object in DataBase
On Sep 5, 8:13 am, Aldo Brett <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> And a controller like this > @fecha = DateTime.new(params[:year].to_i, params[:month].to_i, > params[:day].to_i, params[:hour].to_i, params[:minute].to_i) > @exam = Exam.new(DateTime.now, params[:place])Assuming Exam is an activerecord object you should be passing a hash of attributes (eg :foo => params[:foo], :bar => params[:bar], whereas you are passing 2 arguments Fred> if @exam.save > redirect_to exams_path > else > render :action => ''new'' > end > > Thanks for your help. > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I didn''t understand your solution Fred, thanks a lot for your post. I solved my problem by saving in the database each element of the date as integers, then I read this elements and I build my DateTime element. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Sep-08 07:11 UTC
Re: Error trying to save DateTime object in DataBase
On Sep 8, 5:09 am, Aldo Brett <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I didn''t understand your solution Fred, thanks a lot for your post. I > solved my problem by saving in the database each element of the date as > integers, then I read this elements and I build my DateTime element. > -- > Posted viahttp://www.ruby-forum.com/.I was just saying that you''ve passed two parameters to Exam.new rather than a hash of options. Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---