Displaying 20 results from an estimated 3000 matches similar to: "Seeing what has changed in ActiveRecord"
2006 Mar 10
19
validates_date plugin for ActiveRecord
This plugin gives ActiveRecord the ability to do stricter date checking.
Example:
class Person < ActiveRecord::Base
validates_date :date_of_birth
end
This will ensure that date_of_birth is a *valid* date. The date can be set
initially as a string in any of the following formats:
"2006-01-01"
"1 Jan 06", or "1 Jan 2006"
"1/1/06" # Day /
2006 Jul 15
1
Trouble using date_select with blank options
I want to allow users to enter a day and a month, but not necessarily
a year. i.e. it should be optional.
If I select the day and month, but a blank year and then submit i get:
1 error(s) on assignment of multiparameter attributes
The paramaters regarding the date look like this:
{"date_of_birth(2i)"=>"3",
2005 May 31
2
Form Dates and MultiparameterAssignmentErrors
I''m using the date_select form helper for a date_of_birth field on an
ActiveRecord object. When I try to save a date earlier than 1 Jan 1970,
ActionController punts with
ActiveRecord::MultiparameterAssignmentErrors. The message it gives is
"1 error(s) on assignment of multiparameter attributes". I was able to
catch the exception and look at it, and it is certainly complaining
2012 Oct 23
7
Not updating the updated_at field
This is for Rails 3.1.1
I have a field called last_seen in a model. This field will be updated
when the something about the record is seen in the real world (don''t
worry about this part)
So I go x.update_attribute(:last_seen, Time.now) and the following happens is
UPDATE "blah" SET "last_seen" = ''2012-10-23 08:57:46.179288'',
"updated_at"
2006 Mar 15
1
Strange behaviour of dates
Imagine a crud app that tracks people applying for a loan, here is the
layout I have:
Mysql database:
create table apps (
id int auto_increment primary key,
primary_id int not null,
secondary_id int null,
constraint fk_primary_id foreign key(primary_id) references (contacts.id),
constraint fk_secondary_id foreign key(secondary_id) references
(contacts.id))
create table contacts (
Id int
2009 Mar 17
4
Preventing a submitted hash from ActiveRecord DB store
Hi all,
I have a multi model form (Project with many tasks) and I want to
prevent a task from being saved to the DB if it is empty ie. if there
is no i/p for that task from the user. I tried the following
class Task < ActiveRecord::Base
before_save :check_if_empty
...
def check_if_empty
self.destroy if description.blank?
end
but i get this
TypeError in ProjectsController#create
2012 Jun 14
3
What is the difference between Soap API and REST API?
Regards,
Seeni Rafiyullah Khan A,
*
*
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more
2008 Mar 11
6
saving an ActiveRecord without trigging the callbacks
Hello,
How can I save an ActiveRecord without trigger before_save,
after_save, etc?
Thanks for the help.
--~--~---------~--~----~------------~-------~--~----~
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,
2006 Sep 15
1
In datetime_select, :order does not work, but it works for date_select Why
Hi All
In my project I am to take date of birth from user so I used
datetime_select. It renders three selection boxes, year, month and day. But
I want order as day, month and year. I added :order option for
datetime_select, it renders normal selection boxes with order year, month
and day. Why :order does not work with datetime_select? see my following
code
<%= datetime_select(:user2,
2006 Jun 08
2
how to add plugin to ActiveRecord
I''m trying to set a date field''s day to the last day of the month before
I save it. I can do this successfully now using this code:
class Account < ActiveRecord::Base
def before_save
self.exp_date = last_day_of_month(self.exp_date)
end
# Returns a Date object set to the last day of the current month
def last_day_of_month(date = Date.today)
next_month_str
2006 Feb 01
1
ActiveRecord::FileSystem???
Rails makes working with databases easy with ActiveRecord::Base.
Has anyone written a rails system for working with files so we can do
things like:
class User < ActiveRecord::FileSystem
root_directory "c:/uploads"
file_permissions
directory_permissions
validates_filetype
validates_filesize
validates_filename
before_save
I know about file_column, but I don''t
2011 Oct 14
2
before_save :encrypt_password
I am having a problem finding the best way to make a "before_save
:encrypt_password" conditional.
I have to at times update user model attributes but each time I do this
the password is reencrypted because of the above. I need to
differentiate between when the user is first logging in and the password
does need to be encrypted, and when they are already logged in and the
2006 Feb 10
4
before_save gotcha
Is it will known and accepted that before_save triggers should return
true? I didn''t notice this before but now I see it in the
documentation.
Here is what I''m doing in my model:
def before_save
if self.has_album?
self.visible = self.album.visible?
end
end
That results in the expected result when album.visible? is true - but
not when it is false. To make it
2006 Mar 02
2
How to get mime extension with file_column
Is there a way to get the MIME extension of a file_column field?
Here''s what I want to do (look for comment in before_save method):
class ProductFile < ActiveRecord::Base
belongs_to :product
file_column :file_name
def before_save
self.file_type = # something that returns the MIME type (e.g. image/jpeg)
end
end
TIA
2008 Jun 29
3
Working around/with Restful Authentication
I''m using Restful Authentication, and the code to create a user is
pretty straight forward - there is a before_save action and a
before_create action:
before_save :encrypt_password
before_create :make_activation_code
But for some reason when I try to create a user programmatically in
the controller like this:
User.new(:email =>
2006 Jul 06
2
Custom init. of ActiveRecord objects - best practices
All,
I''m wanting to initialize an ActiveRecord object.
I understand that there is a method called after_initialize that appears
to get called right after the ActiveRecord object is instantiated.
Is after_initialize a Ruby thing or a Rails thing?
Where is after_initialize documented?
Can I pass parameters to it? If so, how?
I want to initialize the "belongs_to" attribute of
2007 Jul 01
1
ActiveRecord: why does 'self.name' and 'name' both work?
I''m trying to figure out why both ''self.name'' and ''name'' work in a
model class. For example:
class Category < ActiveRecord::Base
before_save :set_permalink
private
def set_permalink
# both work
self.permalink = name
self.permalink = self.name
# doesn''t work
permalink = name
@permalink = name
@permalink =
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`,
2009 Feb 07
5
before_save :strip_whitespace => saves with spaces
i used this private function for removing leading and trailing white
spaces from the values.that below function would be called before_save.
when i print the value after it strips.it prints string without any
spaces.but in the table fields it saves with spaces .
waht would be the problem.pls help me
class CompanyInfo < ActiveRecord::Base
before_save :strip_whitespace
def strip_whitespace
2006 Mar 24
2
Access to session data
Greetings,
This, I hope, is a simply answered question.
Based on Agile Web Development with Rails (depot application), I''m
developing a single table application for contact info. There is only
an admin side to this, so there''s always authentication.
Part of the info record (member) is changed_by and changed_at which I
automatically want updated. Changed_at looks after