Displaying 20 results from an estimated 6000 matches similar to: "How to delete a set of records"
2006 Jan 07
8
Using find_by_sql to get the sum of a column
Hello,
I was wondering if there was a method in Rails that returns the sum of a
column. For example, I have a column called ''score'' and writing a SQL
statement such a ''select sum(score) from table_name'' does return the sum
of the values in the column. In the past (not too long ago being a
newbie), I defined all sorts of methods only to discover that Rails
2006 Apr 03
4
How to fake composite primary keys?
I know ActiveRecord doesn''t support composite primary keys, but I need to use
one, and I need it ASAP. I don''t need any composite foreign keys, luckily;
what I have is a table that stores old versions of rows in another table, so
the composite key is an id + date stamp. Would someone tell me a hack I can
use to support this?
--
View this message in context:
2006 Mar 01
4
STI, subclasses and callbacks
I have a STI class tree. I want to set some default values (calculated
values so I can''t set it in the database as defaults) on every created
instance regardless of what subclass is actually instantiated. So I
figured adding a after_create callback in the top class in the hierarchy
should do the trick. It seems it doesn''t get called :(
Code:
class SuperClass <
2006 Jun 11
2
Problem with Acts_As_Attachment
Hi,
I have installed the acts_as_authenticated plugin from technoweenie, but
when I run the tests I get an error (running windoze)
-- create_table(:attachments, {:force=>true})
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require__'':
no
such file to load -- sqlite (MissingSourceFile)
I found the require statement in test/abstract_unit.rb
2007 Mar 28
1
attachment_fu & update_attributes... bug?
It seems that attachment_fu is a pretty popular plugin (it''s great), but
I''ve been having a terrible time trying to figure out an issue when
using "update_attributes". I''m storing files on the file system rather
than in a database.
It seems that when "update_attributes" is called with a new file,
upload_data= tries to copy a file that
2006 Jan 06
3
Getting model class by string
Hello,
I have an interessting problem, I''m not sure how to solve :-)
I have the name of a model in a variable like this:
My model is called Article
My var contains "Article"
Now - How do I get the model class, so I can call Article.find,
Article.new etc ... ?
Greetings,
Gitte Wange
2006 Feb 15
10
STI Question
Hi everyone,
I have 3 types of people (for now):
Staff
Faculty
Students
To break them up into classes, but keep them in the same People table,
I''ve broken them up like so (code and ''ends'' snipped):
class Person < ActiveRecord::Base
class Employee < Person
class Staff < Employee
class Faculty < Employee
class Student < Employee
So, when I insert
2005 Dec 30
9
SELECT MAX
How does one do a SELECT MAX query in rails? I''ve searched and searched and
tried lots of things with no luck.
I want to implement "SELECT MAX(column_name) from table_name
and have it return the maximum value from column_name. I just need to get
that one value, not the whole object...
Thanks for any ideas...
Shelby
_______________________________________________
Rails mailing
2006 Jul 10
18
Deleting join association of has_many :through
I''m trying to use has_many :through, since my join model deserves being
more than just an intersection table.
But when I try to break the association, the break only seems
"temporary":
Let''s say my two tables are Users and Colors, and the join model is
Favorites.
user = Users.find(1)
user.colors.length
>> 2
c = user.colors.first
>> #<Color:....>
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
2008 Dec 19
3
Delete All action
Hi,
What is the best way to delete all members of a model?
For example I have a tasks model and want to put a link in that will
delete all tasks at once. Something like,
@tasks = Task.all
@tasks.each { |task| task.destroy }
Do I need another action for this, and what should the link to it be?
cheers,
DAZ
--~--~---------~--~----~------------~-------~--~----~
You received this message because
2006 Mar 06
20
How painful is the 1.0 -> 1.1 upgrade going to be?
Does anyone have a sense for how painful the 1.0 -> 1.1 upgrade is
going to be for existing apps? I''m finishing up my first real RoR
application with Rails 1.0. I can live with it staying at that level,
but I really want to use the has_many :through attribute to clean up
some of my code.
I''m not particularly interested in edge Rails, mainly because the
documentation for
2005 Dec 30
3
Select SUM(?) Query
When using PHP, I was able to
enter a query against my list of invoices such as :
Select SUM(amount) from invoices where project="123"
This would give me the total amount of all invoices for project 123.
In rails, how would I do this? I tried using "find_by_sql," but
couldn''t figure out how to extract the results out of this. Thanks!
2006 Mar 06
4
Change to set_fixture_class
So, I sat down to use set_fixture_class, and it bombed on the first
thing I tried:
set_fixture_class :content_drafts => "Article::Draft"
I made a quick patch, and I''d appreciate a quick run through your
tests to make sure it doesn''t disturb anything:
http://dev.rubyonrails.org/ticket/4095
As I was typing this, I realized that the string gives us no benefits.
I
2006 Jan 25
11
Executing Ruby code that is inside a string
I would like to put Ruby code inside a string, between <%= %> tags, and
have the code inside the tags executed when the string is displayed. Is
this possible?
--
Posted via http://www.ruby-forum.com/.
2006 Jul 23
8
destroy vs delete
what is the difference between destroy and delete in AR
I am not sure what they mean by
"Destroys the record with the given id by instantiating the object and
calling destroy<http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000866>(all
the callbacks are the triggered). If an array of ids is provided, all
of them are destroyed."
in
2007 Sep 07
6
ActiveRecord::Base#update_all expected behaviour
Hi
I noticed that if in my code I use the following:
Photo.update_all("title = ''Ruby rocks'' ", "id IN (#{@photo_ids})")
All my objects are properly updated but none of the filters/callbacks
are triggered. Is that what''s expected?
I have a before_update filter set on the Photo class and it gets
totally ignored, I guess the only way to solve this
2007 Nov 15
2
Trouble using should_receive
I have this code trying to ensure my reset method works. I want to
make sure all the participants have their destroy method called.
# in my spec for Room
r = Room.new(:name => ''bob'')
r.save
p = Participant.new(:login => ''a'', :password =>
''b'', :password_confirmation => ''b'')
p.room = r
2005 Nov 03
12
Installation of plugins/gems/mix-ins confusion
I''m running 0.14.2 and am a little confused as to the best way to
install mix-ins. I''m specifically using "acts_as_paranoid" as an
example (as it is one of the simpler implementations). It is a gem and
can be "installed" as a gem, but then what''s the best way to integrate
it into my app (require_gem?). I''ve seen recommendations to require it
2010 Sep 29
4
Best image upload plugin?
Hey everyone,
I''ve been dealing with Rails 3, Paperclip and Windows 7 for a few nights
now and don''t feel like I''m actually getting anywhere. I''ve hit config
issue after config issue and it''s a bit of a nightmare. Can anyone
recommend any other gems that will accomplish the same thing?
Thanks, Brandon
--
Posted via http://www.ruby-forum.com/.
--