Comments (8)
If you have not set a value on the attribute then it wil be invalid and output the error message you are seeing. You need assign a value for it to be validated against the restrictions such as on_or_after.
Treat it like other attributes where you need to have a validates_presence_of. Use this in combination with :allow_nil => true option on validates_date, to avoid two errors for the same attribute.
from validates_timeliness.
Thanks for the follow-up, I have debugged into the controller and I see that a string from the UI like this:
May 21, 1999
Is being sent up. Initially, when I played with your gem I thought I had issues with the long US format like that. But when I tried to add a supported mask (per your git wiki) I was informed that the format: mmm dd, yyyy was already supported.
I will verify my claimed experience again.
from validates_timeliness.
The formats in the gem are the supported parsing formats. If you are entering the date in a text field these would applicable. What field type are you entering the date into?
Just a note, the wiki is valid for the latest gem version, v3.0.x. The formats should mostly be the same, however. You can add more that you need.
On 27/05/2011, at 8:31 AM, [email protected] wrote:
Thanks for the follow-up, I have debugged into the controller and I see that a string from the UI like this:
May 21, 1999
Is being sent up. Initially, when I played with your gem I thought I had issues with the long US format like that. But when I tried to add a supported mask (per your git wiki) I was informed that the format: mmm dd, yyyy was already supported.
I will verify my claimed experience again.
Reply to this email directly or view it on GitHub:
#46 (comment)
from validates_timeliness.
I am using a text field like this:
<legend>Availability</legend>
<div>
<%= f.label :publish_on, "Publish on:" %>
<%= f.text_field :publish_on, :class => "date_select_entry" %>
<abbr class="required-indicator" title="Required field">*</abbr>
</div>
I am also using a slightly customized FormBuilder for output:
class FormattedDateFormBuilder < ActionView::Helpers::FormBuilder
def text_field(field_name, *args)
set_value_to_formatted_date field_name, args
super
end
def set_value_to_formatted_date(field_name, args)
opts = args.extract_options!
value = object.send field_name
(opts[:value] = value.strftime("%B %d, %Y")) if is_supposed_to_be_date_value?(opts, value)
args << opts
end
def is_supposed_to_be_date_value? opts, value
value.instance_of?(Date) && opts[:class] == "date_select_entry"
end
end
I adopted this approach before using your gem in order to dry up stuff I needed to drive a JQuery plugin Datepicker.
I will be able to re-check the flow later when I can sit down at the debugger. I will report what I find here so don't burn any cycles yet.
from validates_timeliness.
I updated the Unit Test to use the same string format as I use in my application:
def setup @min_offer = Offer.new :title => "Test Offer", :valid_starting_on => Date.today, :publish_on => Date.today @min_offer.seller = sellers(:seller_two) @min_offer.save end test "update of offer fails when publish on is before today" do @min_offer.update_attributes :publish_on => (Date.today-1).strftime("%B %d, %Y") assert_equal ["Publish on must be on or after #{Date.today}"], @min_offer.errors.full_messages end
And it now produces the same shorter message as in the application because now my Unit Test fails like this:
<["Publish on must be on or after 2011-05-26"]> expected but was
<["Publish on is not a valid date"]>.
Do I need to do this?
ValidatesTimeliness::Formats.add_formats(:date, "mmm dd, yyyy")
If I do use this do I need this? (Because I am not using the plugin parser since my date format is parsed by Ruby Date)
config.use_plugin_parser = true
from validates_timeliness.
What is the value of publish_on just before the assert?
from validates_timeliness.
It is nil as demonstrated by this output:
Publish_on is now [] and is class NilClass
Produced by using this in the test:
puts "Publish_on is now [#{@min_offer.publish_on}] and is class #{@min_offer.publish_on.class.name}"
from validates_timeliness.
So the value is still nil and therefore an invalid date. The on_or_after value is not assessed if the value is nil.
It is invalid because the validation checks if you had attempted to assign a value by checking if publish_on_before_type_cast value is not nil and publish_on is nil. In that scenario the string has not been parsed properly.
I will leave it for you to investigate further.
On 28/05/2011, at 6:01 AM, [email protected] wrote:
It is nil as demonstrated by this output:
Publish_on is now [] and is class NilClassProduced by using this in the test:
puts "Publish_on is now [#{@min_offer.publish_on}] and is class #{@min_offer.publish_on.class.name}"Reply to this email directly or view it on GitHub:
#46 (comment)
from validates_timeliness.
Related Issues (20)
- Useless code in initializer file created by Installation guide HOT 2
- No configuration required per thread (compatibility with timeliness 0.4.0+ HOT 7
- No support for midnight with :time type HOT 1
- NoMethodError: undefined method `deduplicate' with ActiveRecord 6.1 HOT 3
- Doesn't work with Ruby 3.0 / Rails 6.1 (PR attached) HOT 5
- Gem in 5.0.0 version not execute "timeliness" validations in ActiveRecord models HOT 12
- Update `CHANGELOG.rdoc` for v5.0.0 HOT 1
- Check time_zone_aware_types HOT 3
- Plans to release a official 6.x version HOT 3
- `add_error` call with wrong number of arguments HOT 2
- Issue on engine test load HOT 2
- ArgumentError: wrong number of arguments (given 3, expected 1..2) on records.error.add HOT 8
- Locale for Vietnamese HOT 2
- Rails 7 Deprecation Warnings HOT 6
- Rails 7 dependency - activemodel HOT 4
- Please support Rails 7 then cut a new version HOT 1
- Additional maintainer needed HOT 2
- Support for Rails 7 HOT 4
- Is there any way that I can make sure that ranges are exclusive?
- Handle when the passed value is not a Date value. when it's a Numeric
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from validates_timeliness.