similar to: Validation on ActiveRecord destruction

Displaying 20 results from an estimated 3000 matches similar to: "Validation on ActiveRecord destruction"

2006 Aug 02
6
Legacy association without primary key
I have a legacy database with which I need to interface. There are two tables that are joined together by two fields, and neither field is the primary key of its associated table. Is constructing an association between these tables beyond the capability of Rails? -- Posted via http://www.ruby-forum.com/.
2009 Apr 02
3
error_messages_for does not display the error
Hi all I''ve approached Rails since a couple of months to develop a quick application for my company. Fantastic framework. As every noob, I do have some gaps to cover. The one which is giving me a little frustration, generated by my lack of knowledge is as follows. I need to make sure the region object is not deleted if there are countries associated with it. I solved this by putting a
2006 Jun 29
1
before_destroy & verification
Hey, probably an easy question but, I''m trying to get a method to run "before_destory" for a model, and I want the method to throw an error, and not delete the object from the database, if a certain condition is held Obviously, I can just raise an error and rescue it... but for some reason I can''t get <% error_messages_for ''model" %> to catch
2006 May 16
2
Validate Before Delete
I have an Order model with a ''status'' column. What I want to be able to do is validate that the status of the Order is not completed before it is allowed to be deleted. I tried the following method in my Model, but it appears that this only works for an :update or :create on the record. Anyone know how to do this, and if it should be in the model or the controller?
2006 Apr 28
7
a simple problem but difficult
how can i access to a collection that was created in the same control and the data that a want to access isn?t the id the collection has : id, usuario, comandancia comandancia is the data to access the question is how to access comandancia in @acceso this code is wrong : def new @catelemento = Catelemento.new @acceso= Catacceso.find(:all, :conditions
2006 Dec 07
2
validate_on_destroy ?
What''s the best way to validate_on_destroy. Rails only seems to include validate_on_create and validate_on_update methods. I don''t want to resort to doing: before_destroy do |j| raise "There is an error" if j.etc end Is there a way of finding out what action (create/update/destroy) is being performed if I use the ''validate'' method? -- Posted via
2006 Mar 24
2
before_destroy not called
Hello, I''m trying to intercept delete call in my model but before_destroy callback is never called... Somebody knows why ? Thanks The controller : def delete Image.delete(params[:id]) redirect_to :action => "list" end The model : class Image < ActiveRecord::Base set_table_name "publish_images" belongs_to :article before_destroy :on_destroy
2006 Jul 20
5
How can I make has_many prevent a delete that would lead to orphans?
e.g. class Asset < ActiveRecord::Base validates_presence_of :asset_number, :make, :model, :location, :name, :serial_number validates_numericality_of :asset_number validates_uniqueness_of :asset_number belongs_to :user belongs_to :location belongs_to :asset_type, :foreign_key => ''type_id'' end class Location < ActiveRecord::Base validates_presence_of :name
2005 Oct 23
12
Showing a neat error message
Hi All, I''m trying to prevent users from deleting a folder that has contents like this: class Folder < ActiveRecord::Base has_many :myfiles has_many :folders belongs_to :folder validates_uniqueness_of :name, :scope => "folder_id" before_destroy :dont_destroy_folder_with_contents def dont_destroy_folder_with_contents if Folder.find(id) != nil ||
2006 Feb 18
5
don''t destroy last user
How would I stop the last user being deleted. The following code doesn''t work. before_destroy :dont_destroy_last_user # Don''t delete user if it the last one def dont_destroy_last_User raise "Can''t destroy last user" if User.length < 1 end -- Posted via http://www.ruby-forum.com/.
2007 Sep 20
2
Superimposing vector polygons over raster grid in a plot
Hello: I would like to superimpose vector polygons (state outlines) from a Shape file on top of a satellite image, imported into a SpatialGridDataFrame from GEOTIFF via gdal_translate and readGDAL. When I plot polygon and point shape files in R, into SpatialPointDataFrame and SpatialPolygonDataFrame, the two feature sets line up geographically, so it seems logical that a SpatialGridDataFrame
2008 Jul 04
2
How do change catalog before catalog is delted?
In my rails application,there are two models:post and catalog. One post has a catalog,and one catalog has many posts. When I delete a catalog,the posts belongs to the catalog will not be shown normal,for it''s catalog is no existed. Now I want to create(if the ''Defalut catalog'' is not existed) a ''Defalut catalog'' in catalogs table,and make the
2007 Jun 29
1
Speeding up :dependent => :destroy
I have a tree of models that represent a book. Looks like this: book sections documents paragraphs index entries glossary entries footnotes index entries glossary entries These are all models with has_many from parent and the child has belongs_to. They also all have dependent => :destroy
2006 Mar 13
6
:dependent => :destroy
Hi, There is something I don''t understand about :dependent => :destroy. I hope someone can help me. Consider this code: class Folder < ActiveRecord::Base has_many :myfiles has_many :folders has_many :group_folders, :dependent => :destroy validates_uniqueness_of :name, :scope => "folder_id" validates_presence_of :name before_destroy
2005 Jan 04
6
OT: List of VoIP providers?
I have been looking around for VoIP providers but have not found a good listing. Is there no "yellow pages" for VoIP providers? Google mostly returns services like Vonage, Packet8, NuFone, ect. None seam to be very reseller friendly and none offer LNP or local DID's for my area. Anyone know of a list (even a partial one) Jeromie Reeves
2006 Apr 01
2
ActiveRecord callbacks not called
Hi, there must be something wrong somewhere in my unit test because there''s a model I can''t have any callback executed on. In my unit test I do @image = Image.new @image.set_uploaded_file({:file => uploaded_file("pic1.jpg","image/jpeg","article-picture.jpg"), :article_id => @article.id, :title => ''Titre
2006 Jan 07
8
exposing id''d
I have been working on a small app that started with some scaffolding. Some of my actions still have the structure where the id''s of things are passed on the url for gets. Whats the best way to avoid the security problems that this creates? I am sure that there are many pages written on this topic but I guess I have been searching for the wrong things. Thanks Gareth -- Posted via
2005 May 08
1
"validation" on destroy
I''m building a little application with Rails, and I''m becoming a huge fan of the validations in ActiveRecord. Recently, though I ran into a problem which to me feels like a job for Validations, but I can''t see a way to use them. My model consits of a Trade object, which represents either buying or selling some security. I need to require that at no point has a user
2006 Jun 23
10
Don''t un-admin the last administrator
I have a User class with a field called admin which is a boolean that determines if the user is or is not an administrator. I want to make it impossible for the last administrator for an account to be removed from the system. I need to protect against this both when deleting a user and when editing a user as you can revoke a user''s administrator privileges via a form. User
2008 Mar 17
4
RSpec''ing model association callbacks
Hi all, i''m learning rspec and i must admit i really love it. But at the time i started learning it, i already developed my models classes and their callbacks. Now i''m trying to get a 100% coverage of my code but i cannot reach it because i do not understand how to spec my callbacks. Look at this for example: ----------------- User Model class User < ActiveRecord::Base