similar to: How to write the method before_destroy and the test

Displaying 20 results from an estimated 5000 matches similar to: "How to write the method before_destroy and the test"

2006 Nov 17
4
before_destroy and sessions
(Semi-newbie.) I want to ensure a user''s able to destroy only his own objects. I''ve set session info at login: session[:user_id] = user.id Now I try this in the model of my deletable objects: before_destroy :destroy_your_own def destroy_your_own raise "Can''t delete that!" unless session[:user_id] == self.user.id end which snags EVERY attempted
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
2008 Jan 09
4
Using Prototype - Getting Javascript Error - "Object doesn't support this property or method"
I have the following javascript being called on my site and I am getting a Javascript error - "Object doesn''t support this property or method". The error is invoked on the line that has - "listItems = $ ("vidList").childElements("li");". The purpose of the Javascript is two fold: ''swapVideo'' to change the Youtube video and
2006 Apr 14
5
One Controller, Many models
Hello all, I am working on a app right now that is going to replace a paper form process out client has. This process has quite a few forms (about 30) and different groups of forms (section) need to be filled out based on what information is required from the user. For example, here is a possible process of 2 users: user 1 user 2 Section 1 Section 1 Section 2 Section 2
2008 May 18
0
Spec a before_destroy callback in Sequel
Hi I''m struggling to find a neat way to spec this. The Sequel ORM doesn''t support automatically destroying dependent models. It''s easy enough to do in a callback though: class Changeset < Sequel::Model has_many :migrations, :class => DataModel::Migration before_destroy do migrations.each { |m| m.destroy } end # ... end
2006 Feb 15
2
extending rails via /lib - problems
I wanted to group some functions which I use in some models in one place. Controllers have application.rb and views have helpers but I couldn''t find anything about models. Using the /lib directory seemed to be the only way. Alright... so I have something like this: /lib/code.rb class ActiveRecord::Base def method_a(n) ....... end def method_b(n) ........ end end
2007 Mar 14
0
before_destroy return false, but dependent are destroyed
I have a problem with before_destroy deleting by dependent records, even through I return flase. ... has_many :users, :class_name => ''Editor'', :as => :editable, :dependent => :destroy ... def before_destroy unless self.has_access?(99) errors.add_to_base "Destroy permissions error!" return false end end When I remove the dependent
2005 Dec 29
5
Extracting SQL and Rebuilding from SQL?
Hello- With a database filled with several customers'' datasets, I thought it would be a nice feature of my app''s backend interface to be able to extract (and optionally delete) the data from a single customer. It would then also be nice to rebuild that data from the stored info. What''s a good way to do this efficiently? If all the ":dependent => true"
2005 Jul 24
0
cancelling before_destroy
According to the documentation, if I return false in a model''s before_destroy method then it should cancel the action. Although I know it is reaching and running this code, it deletes the object despite the "return false". I''m sure this were a bug it would have been noticed by now so I must be missing something but I cannot imagine what. Even in the simplest
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
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 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 Aug 01
3
Validation on ActiveRecord destruction
Rails has many built in validation methods to ensure that an ActiveRecord instance cannot be created or updated under certain situations (typically caused by invalid data). However, I can find no methods to govern whether an ActiveRecord instance can be destroyed. Essentially, I wish an error to be raised when a user tries to delete an ActiveRecord without first adhering to a certain set of
2010 Sep 02
5
Re: Exclude ActiveRecord in Rails3
What''s the best way to exclude ActiveRecord in Rails3? In Rails2, one could just do: *config.frameworks -= [ :active_record ]* in the configuration block in environment.rb. Is it possible in Rails3? Thanks. Anuj -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to
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/.
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
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 Nov 30
3
model stubs with view/controller specs: error_messages_for??
How would I set up a model stub so that <%= error_messages_for ''some_model'' %> doesn''t complain? I started going down this road: @some_model.stub! (:errors).and_return(ActiveRecord::Errors.new) but it seems like a long, hopefully uneccessary road. Cheers, Michael
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 Apr 26
6
Immediate help needed
I have posted this previously also but haven''t received any help. So, if somebody could look into it and guide.. I want to validate the extension of files that I am uploading. Like I want only the doc/pdf files to be uploaded.. Thanks in advance. -- Posted via http://www.ruby-forum.com/.