I have looked around the net and can’t find the answer to this
question. I have a date column that is allowed to be null. How do I
allow the user to enter a null date in the form?
Old hand at Ruby, new to RAILS…
I have looked around the net and can’t find the answer to this
question. I have a date column that is allowed to be null. How do I
allow the user to enter a null date in the form?
Old hand at Ruby, new to RAILS…
On Jul 16, 2007, at 17:10 , [email protected] wrote:
I have looked around the net and can’t find the answer to this
question. I have a date column that is allowed to be null. How do I
allow the user to enter a null date in the form?Old hand at Ruby, new to RAILS…
You might try the Ruby on Rails mailing list:
http://groups.google.com/group/rubyonrails-talk
Michael G.
grzm seespotcode net
[email protected] wrote:
I have looked around the net and can’t find the answer to this
question. I have a date column that is allowed to be null. How do I
allow the user to enter a null date in the form?
AFAIK, there isn’t a preset, easy way to do it. Here’s my 2 ways:
Like so: (Note: missing labels, etc)
<%=date_select 'your_record_object', 'your_date_field' %>
<%=check_box 'options', 'your_date_field_is_null' %>
Then in your controller, test for the checkbox and set the date field to
nil if applicable.
Like so: (this could be prettier)
@record = YourRecordObject.find(params[:id])
if request.post?
if @record.update_attributes(params[:your_record_object])
if params[:options].has_key?('your_date_field_is_null') &&
params[:options]['your_date_field_is_null'].eql? '1'
@record.update_attribute(:your_date_field, nil)
end
end
end
Like so: (this could be prettier)
@record = YourRecordObject.find(params[:id])
if request.post?
if params[:your_record_object][:your_date_field].empty?
params[:your_record_object][:your_date_field] = nil
else
params[:your_record_object][:your_date_field] =
params[:your_record_object][:your_date_field].to_date
end
if @record.update_attributes(params[:your_record_object])
flash[:notice] = "Your Record Object was updated successfully."
end
end
–
Travis W.
“Programming in Java is like dealing with your mom –
it’s kind, forgiving, and gently chastising.
Programming in C++ is like dealing with a disgruntled
girlfriend – it’s cold, unforgiving, and doesn’t tell
you what you’ve done wrong.”
how about date_select(blah, blah, :include_blank => true)
[email protected] wrote:
I have looked around the net and can’t find the answer to this
question. I have a date column that is allowed to be null. How do I
allow the user to enter a null date in the form?Old hand at Ruby, new to RAILS…
On Jul 17, 6:42 am, Matthew R. [email protected] wrote:
how about date_select(blah, blah, :include_blank => true)
Ooh, nifty. Thanks!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs