Hello Everyone,
I am trying to use the date_select() form helper method per AWDWROR.
In
the DB the column "entry_date" is a datetime.
So using the below form, in part
============ app/views/entry/index.rhtml ==<tr>
<th>date</th><td><%= date_select("entry_date",
:start) %></td>
</tr>
how do I get it into the AR instance?
============ app/controllers/EntryController.rb ======def create
@entry = Entry.new(
:entry_date => params[:entry_date]["start"],
:task_id => params[:task][:id],
:description => params[:description]
);
end
This gives me "entry_date cannot be null" from mysql.
The backtrace/debug dump on the error page mentioned that
Parameters: ....
"entry_date"=>{"start(1i)"=>"2007",
"start(2i)"=>"4",
"start(3i)"=>"25"}
where did that (1i), (2i) stuff come from? what does it mean?
In any case I was hoping to use a DHTML calendar pop-up for this date
entry, but wanted to get this working for the prototype. So if you
can
help I appeciate it
thanks
Sam
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
# ----- View
<h1>Editing book</h1>
<%= error_messages_for :book %>
<% form_for(:book, :url => book_path(@book), :html => { :method
=> :put }) do |f| %>
<p>
<b>Created at</b><br />
<%= f.datetime_select :created_at %>
</p>
<p>
<b>Title</b><br />
<%= f.text_field :title %>
</p>
...
...
...
<p>
<%= submit_tag "Update" %>
</p>
<% end %>
<%= link_to ''Show'', book_path(@book) %> |
<%= link_to ''Back'', books_path %>
# ---- Controller
# POST /books
# POST /books.xml
def create
@book = Book.new(params[:book])
respond_to do |format|
if @book.save
flash[:notice] = ''Book was successfully created.''
format.html { redirect_to book_url(@book) }
format.xml { head :created, :location => book_url(@book) }
else
format.html { render :action => "new" }
format.xml { render :xml => @book.errors.to_xml }
end
end
end
P.S. If you would prefer to let Rails completely handle the entry_date
for you just change the name of the column in the DB to created_at
(for datetime) or created_on (for date). Then you can remove the
date_select entirely from the form and Rails will automatically set
the field to the current date and time when the record is created.
You can also use updated_on and updated_at to create auto updating
date and time stamps.
On Apr 25, 9:33 pm, sbeam <szb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hello Everyone,
>
> I am trying to use the date_select() form helper method per AWDWROR.
> In
> the DB the column "entry_date" is a datetime.
>
> So using the below form, in part
>
> ============ app/views/entry/index.rhtml ==> <tr>
<th>date</th><td><%= date_select("entry_date",
:start) %></td>
> </tr>
>
> how do I get it into the AR instance?
>
> ============ app/controllers/EntryController.rb ======> def create
> @entry = Entry.new(
> :entry_date =>
params[:entry_date]["start"],
> :task_id => params[:task][:id],
> :description => params[:description]
> );
> end
>
> This gives me "entry_date cannot be null" from mysql.
>
> The backtrace/debug dump on the error page mentioned that
> Parameters: ....
> "entry_date"=>{"start(1i)"=>"2007",
"start(2i)"=>"4",
> "start(3i)"=>"25"}
>
> where did that (1i), (2i) stuff come from? what does it mean?
>
> In any case I was hoping to use a DHTML calendar pop-up for this date
> entry, but wanted to get this working for the prototype. So if you
> can
> help I appeciate it
>
> thanks
> Sam
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Thanks - maybe I should state the bigger picture of what I am trying to do - its basically an event logger. Really this is pretty simple but I am new at Ruby and Rails so life is hard now. So users can choose a date on which the event occurred, that is taken care of my the date_select field (for now) then they need to choose a start and end time within that date. So for this I am using text fields because its easier for them to type. But in the DB I would like to save these as timestamp fields because there is going to be a lot of reporting and statistics that goes on based on the data. So in the DB I have =============mysql> desc entries; .... | entry_date | date | NO | | | | | start_time | timestamp | YES | | NULL | | | end_time | timestamp | YES | | NULL | | .... ============= and in the controller, I am getting the entry_date in OK as you indicated. But to get a timestamp for the start_time and end_time, I need to 1) get the date from params[:entry_date] as a Date object (I think) at time 00:00? 2) add the given hours and minutes to the Date 3) convert that to a unix_timestamp which mySQL will be happy with so far I am stuck on step 1 ;) step 3 might not be needed, I''m not sure yet. Any pointers? how would the seasoned pro go about this? thanks Sam --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> Any pointers? how would the seasoned pro go about this?Well, a seasoned pro would likely use a JavaScript/DHTML date and time picker with all the fancy bells and whistles. Then use it''s resulting date string representation to parse into a Ruby Time object. That is if they choose not to use the build in date time selectors Rails provides. On Apr 25, 11:28 pm, sbeam <szb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks - maybe I should state the bigger picture of what I am trying > to do - its basically an event logger. Really this is pretty simple > but I am new at Ruby and Rails so life is hard now. > > So users can choose a date on which the event occurred, that is taken > care of my the date_select field (for now) > > then they need to choose a start and end time within that date. So for > this I am using text fields because its easier for them to type. But > in the DB I would like to save these as timestamp fields because there > is going to be a lot of reporting and statistics that goes on based on > the data. > > So in the DB I have > =============> mysql> desc entries; > .... > | entry_date | date | NO | | > | | > | start_time | timestamp | YES | | NULL > | | > | end_time | timestamp | YES | | NULL > | | > .... > =============> > and in the controller, I am getting the entry_date in OK as you > indicated. But to get a timestamp for the start_time and end_time, I > need to > 1) get the date from params[:entry_date] as a Date object (I think) at > time 00:00? > 2) add the given hours and minutes to the Date > 3) convert that to a unix_timestamp which mySQL will be happy with > > so far I am stuck on step 1 ;) > > step 3 might not be needed, I''m not sure yet. > > Any pointers? how would the seasoned pro go about this? > > thanks > Sam--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Thursday 26 April 2007, Robert Walker wrote:> > Any pointers? how would the seasoned pro go about this? > > Well, a seasoned pro would likely use a JavaScript/DHTML date and time > picker with all the fancy bells and whistles. Then use it''s resulting > date string representation to parse into a Ruby Time object. That is > if they choose not to use the build in date time selectors Rails > provides.well I was going to use a DHTML timepicker widget but thought prototyping with this would be easier. But I have since found out, not so much. my current creation looks like this for the curious: http://pastecode.com/28881 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---