Displaying 20 results from an estimated 1000 matches similar to: "Compute date during before_validation_on_create"
2012 Jul 10
1
calculating the difference between days?
Hi List,
I have one column of beginning dates and one column of ending dates, I want
to find their difference. And I want to ignore the trailing zeros,
basically everything after the first colon mark.
Begin_date End_date
01JAN2000:00:00:00:000 02FEB2002:00:00:00:000
24MAR2012:00:00:00:000 18MAY2012:00:00:00:000
01OCT2003:00:00:00:000
2006 Apr 18
3
ez_where query question
I''m having fun composing queries with ez_where, but am stuck on how to
formulate the following using the ez syntax:
(begin_date >= ? OR end_date >= ?) AND (description LIKE ? OR name LIKE ?)
There are two clauses, each containing OR operators (the ez ''any'' syntax)
but both clauses must evaulate to true for a match.
Can anyone suggest the proper way to construct
2012 May 26
2
before_create is after_validatation :on => :create , when it should be before_validation :on => :create
In ActiveRecord''s callbacks, methods within a before_create callback
are called after the validation, but before the model is created.
This was an intentional design decision, but I think it was the wrong
one. What do you think?
When I think of before_create, I think of before_validation :foo, :on
=> :create, but, by default, before_create is synonymous with
after_validation :foo,
2008 Oct 14
4
replace_html not working
hallo, everyone
can anybody help me? i did add my code under ENGINES as a module in a
project. before the change , all worked . and the differenz between
both is only about application''s environment,
before is
Ruby version 1.8.6 (i486-linux)
RubyGems version 1.1.1
Rails version 2.0.2
Active Record version 2.0.2
Action Pack version 2.0.2
2006 May 24
1
Observer behavior differences between DEV and TEST environments ?
Hi all !
I''m having an issue and I can''t seem to make heads or tails of it.
I am attempting to add an observer to a model object. I created
app/models/greenback_transaction_observer.rb, inherited from
AR::Observer, defined methods, registered in config/environment.rb,
but things don''t work...
So, I took a step back and put in the following code:
class
2006 Feb 28
6
Activerecord equivalent of the SQL "SUM()" function.
Search doesn''t seem to be working, so forgive me if I''m covering old
ground here, but I''m having a difficult time figuring out how to
implement a "SUM()" function using Active record. Obviously, I could
just create a query, but I''d rather make it part of my active record
object.
Basically I have an object called "Report <
2012 Nov 10
6
Suggestion: `before_save on: :create` should either work or raise an exception
There''s a small inconsistency in ActiveRecord''s callback syntax that has
tripped me up before. It wouldn''t be a big deal, but it can lead to a
silent failure. I''d like to suggest that it either be made consistent or be
made to fail loudly.
The issue is that to do something before validating, but only when
creating, you use `before_validation on: :create`,
2010 Mar 31
0
Date format in Rails 3.0 using sqlite3
Hi,
I am new to Ruby and Rails, so I don''t know if this is my fault, but
maybe this is a bug in Rails (I''m using Rails 3.0 beta) which should be
reported.
I have following search statement:
[code]events = CalendarEvent.find :all, :conditions => { :target_date =>
begin_date..end_date }[/code]
which produces following sqlite output:
[code]SELECT
2005 Dec 30
2
before_create question
I have the following models: User, Registration, Event.
User has_many Registration, Event has_many Registration, and
Registration belongs_to User and Registration. So far, so good.
There''s a registration deadline on a Event though, a few days before
the Event occurs.
So, I have this:
class Registration < AR
def before_create
errors.add_to_base("Registration deadline has
2006 Jun 15
1
callback object problem
I''m trying to create a separate class to do validation so that about 10
models can use the same date validation. I have tried to use the
example from the agile book but it''s not working. Here''s what I have:
app/models/date_callbacks.rb
class DateCallbacks
def before_validation(model)
if model.start_date > Date.today
model.errors.add(:start_date, "must
2006 Jan 16
1
Bundled resource -- something I''m missing
I have a decoupled form embedded in my pages ? a search box that has date
fields ? and of course the search fields are not in my model. However,
picking dates is a great use for the Dynarch calendar. It seems that by
using the syntax:
<%= render :partial => ?filter_box? %>
In my view and...
<%= dynarch_date_select ''filter_box'', ''begin_date'' %>
2006 Jul 22
7
Validation with has_many
I have two problems. I have a comment that has_many uploads. Before
saving the comment, I want to be sure that the upload(s) has passed
validation, but I also need to validate in other ways. For example, I
do not want to save the comment if there is no comment or upload. Or, I
do not want to save the comment if the image has been uploaded
previously (comparing md5s with past upload md5s
2009 Dec 03
1
Ann: ArEvents
Hi,
I needed to be able to add actions to be taken during the lifecycle of
ActiveRecord object, but needed to configure it dynamically.
Observers were not flexible enough and I ended up developing ArEvents,
which lets you easily attach and detach event listeners, the events
correspond to the active record callbacks.
If you have an existing model, just include the ArEvents module:
2006 Jul 05
2
Serialized object behaves weird
Hi!
I got a class named EinsatzFilter which I serialized to session. Before
saving to session it works afterwards I keep getting the message:
"undefined method `to_s'' for #<Person:0x38c6ab8>". "Person" is a from
ActiveRecord::Base inherited class.
Code:
class EinsatzFilter
include ApplicationHelper
attr_reader :personen, :monat, :projekte, :kunde
2006 Jan 17
4
find_by_sql column ordering defect?
Hello.
I have a program that accesses a metadata (translation) table for column
names as well as the ordering of columns for a specific model. Also in
there is a collection of bool options such as column_visible_on_form,
column_visible_on_screen_quicklist etc. The idea is that our customer
can specify to a certain extent how their layout/user interface will
appear.
To accomplish this, I use
2006 Jun 04
5
Manipulating form inputs?
I have created a scaffold Admin/Radicals for doing CRUD. However, I''m
not sure exactly where the scaffold uses the save() method. For a new
entry, it creates form "radical" referencing method create(). The code
for create() is as follows:
def create
@radical = Radical.new(params[:radical])
if @radical.save
flash[:notice] = ''Radical was
2006 Jun 25
1
Sorting ferret results by column
I have the acts_as_ferret plugin installed. Everything searches great,
but I would like to limit the results (i.e. by ''end_date'') and sort them
(by ''end_date''). ''end_date'' is a valid column in my "posts" table.
Here''s the code I have already:
@posts = Post.find_by_contents(params[:query])
params[:query] comes from a form. I
2006 Jun 14
4
Using now() to determine what should be displayed
I''m trying to create a paginated list that will take note of the
"end_date" field in my table. This is what I have:
@post_pages, @posts = paginate(:posts, :per_page => 10, :order_by =>
''end_date'')
in the controller. And for the view:
<h1>Posts ending soon</h1>
<ul><% for post in @posts do %>
<strong>Post Title:
2006 Feb 09
17
complicated finds are eating my sole
I abandoned ruby way for find_by_sql and still can''t get this...
@myplacement = Placement.find_by_sql(
"select * from placement where
:intake_date >= beg_intake_date
and
:intake_date <= end_intake_date")
just a simple date range...it''s killing me - If I knew how to load
placement controller into irb, I could probably try out finds
interactive mode...
Thanks
2006 Jul 17
1
How to DRY up validates_presence_of
Given the case of validating the presence of an attribute and then
performing other tests on said attribute, how do you go about not having
to check for nil in the other tests?
Example:
validates_presence_of :start_date, :end_date
validate :validate_start_date_before_end_date
def validate_start_date_before_end_date
# without this check an exception will be thrown on access to the