Displaying 20 results from an estimated 600 matches similar to: ":dependent => :destroy"
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 23
13
Check if a saved user''s name is admin
Hi all,
I have a question about this method in my User model:
# Returns true for the (saved) user called "admin"
def is_the_administrator
true if save and name == "admin"
end
The method returns true if the user''s name is admin. However, I only want to
return true if the state of the object is "saved", so I call the save method
first.
I''m
2006 Jan 11
3
Just update 1 field
Hi All,
I wonder how I can get rails to update just one field when I do Myfile.save.
Right now this happens when I do a Myfile.save:
UPDATE myfiles SET `folder_id` = 0, `filesize` = 1, `data` =
''2f7573722f6c6f63616c2f6d ... f7061636b65743d33324d'', `user_id` = 0,
`date_modified` = ''2006-01-11T23:33:57+0100'', `filename` =
''mysqlscripts.sql''
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 05
2
ActiveRecord callbacks not happening
Hi,
I have a model class like so:
class Candidate < ActiveRecord::Base
validates_presence_of :name
@@index = FerretConfig::INDEX
def self.after_destroy
puts "Ferret: after_destroy called"
@@index.query_delete("+id:#{self.id} +ferret_class:#{self.class.name}")
optimize_index
end
end
But when I delete a record, the after_destroy is never called.
2007 Feb 28
5
How to use find_options in multi_search
Hello everyone,
I''m using multi-search to search in some attributes of two classes. One
of the attributes is the id of the customer. For each multi_search I
want to do a give the id of the current customer as a parameter. This
should only return results for the given customer.
My current code looks like this:
Folder.multi_search(@search_query, [Myfile])
I noticed in the API you can
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 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
2006 May 18
3
access to an ApplicationController property from a view
Hi there,
How is it possible to get access to an ApplicationController property
from a view?
Consider this (simplified) situation:
class ApplicationController < ActionController::Base
def folder_id
@folder_id = params[:id]
return @folder_id
end
end
class FolderController < ApplicationController
def show
@folder = Folder.find_by_id(folder_id)
end
end
So far,
2008 Dec 04
2
Cucumber and Rcov
I am now trying to get rcov to work for me, without much success. I
stole the rake task code from the cucumber site:
desc "Run all features"
task :features => "features:all"
task :features => ''db:test:prepare''
require ''cucumber/rake/task'' #I have to add this -mischa
namespace :features do
Cucumber::Rake::Task.new(:all) do |t|
2006 Jan 16
23
Read data from Excel
A client of mine has a ton of data stored in Excel spreadsheets. I''m
building a web application for her (backed by a real db of course) and want
to import all that data. Is there a library available to read data from
Excel? Is there an easy way to upload the spreadsheets and then read the
data?
Thanks,
Ken Kousen
--
Kenneth A. Kousen, Ph.D.
President
Kousen IT, Inc.
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
2006 Jan 16
4
Question about self and private
Hi!
There''s something I don''t understand yet about static/private methods. I
hope someone can explain...
E.g.:
class SayHello
def hello(who)
puts "Hello, " + who + "!"
end
def self.say(words)
puts words
end
end
hello = SayHello.new
hello.hello "World" : Hello World!
hello.say "hi" : Error
SayHello.say
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/.
2012 Dec 06
2
Bye Bye, Observers
Observers will be no more as of Rails 4, farewell, never been much of a
fan. However, I''m using it in one of my gems which enables model attributes
for use with a WYSIWYM editor. The resulting markup is persisted, but in
order to use it in a view, it has to be nokogiried in a helper which
fragment caches the result. This cache has to be zapped once the model
instance is either
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
2005 Nov 23
8
Compiler OR Obfuscator for RoR applications?
Hi folks,
I''m a newbie in the Ruby land, The Ruby language and RoR looks really
great but I think in my situation there is a problem, we are an ISV
that sells web application and we don''t want our clients see our
source code, I searched the web but couldn''t find any way to compile
and\or obfuscate ruby code (in web (RoR)), is there such tool
available for the language?