Displaying 20 results from an estimated 30000 matches similar to: "2 ActiveRecord Calculations"
2006 Jun 03
6
Calculating row COUNTs
hi everyone,
I''m trying to do a simple calculation in my rails project. I would like
to find all rows in a table that match the given id of another table
(ie. comment_id) and has the value = 1 ("value" is a field in the
table), then add those values up. Next find the same rows with the
value = -1 and add those values up also. Finally, I would like to find
the total.
2006 Jun 08
5
Displaying Calculation on Index
Hi, I am trying to create a simple point system and display the total on
my index page. So I have my db basically setup like this:
Posts
id, body, created_at, user_id
Post_points
id, post_id, user_id, created_at, value
So as you can see I am allowing other users to create points on the post
and my db will store who gave the point as well. "value" is the point
value which can
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 Mar 22
3
Which JavaScript effect is this?
http://canadaonrails.com/ (when you hover over news and events)
I''ve seen this implemented on a few rails sites now and I was just
wondering if it is just a simple javascript from the prototype library.
Does anybody know of any links on how to do this?
Thanks in advance!
--
Posted via http://www.ruby-forum.com/.
2006 Jun 01
7
Active Record Basics - Making it commentable
hi everyone, I hope someone can help me out with some active record
basics? I''ve been banging my head for the past 4 hours and I can''t seem
to get it to work.
I am trying to add comments to a caption (just like how one adds a
comment to a post in a blog). I seem to be able to read posts just fine
from the DB, however, I can''t use the "recordComment"
2009 Jan 30
2
rescue ActiveRecord::RecordInvalid
Hi all,
I am using is_attachment plugin, but I will always end up with this
error:
RuntimeError in PostsController#create
BLAH
which was caused by:
version.filename = file_name_for_version(version_name)
begin
version.save!
rescue ActiveRecord::RecordInvalid
raise "BLAH"
end
end
RecordInvalid was raised by save! because is invalid.
Does anyone know why? I am uploading
2006 Jul 27
1
ActiveRecords::Calculations
I have my Model<ActiveRecord::Base ,
but whenever I try something like
Model.calculate() or Model.maximum ...
I get NoMethodErrors.
Why can I use any of the other ActiveRecord methods, but none from
Calculations
and what do I do to remedy this?
thanks
--
Posted via http://www.ruby-forum.com/.
2006 Jul 27
0
ActiveRecords::Calculations trouble
I have my Model<ActiveRecord::Base ,
but whenever I try something like
Model.calculate() or Model.maximum ...
I get NoMethodErrors.
Why can I use any of the other ActiveRecord methods, but none from
Calculations
and what do I do to remedy this?
thanks
--
Posted via http://www.ruby-forum.com/.
2006 Jul 04
1
Quick question: Iterate through a collection - no duplicates
Hi, is there a simple way to iterate through collection and not include
duplicates?
Thanks in advance.
Jordan
--
Posted via http://www.ruby-forum.com/.
2005 Dec 18
2
Could someone host my 1mb rails app??
Hi Everyone,
Would someone be able to do a huge favor for me and host a very small
1mb rails app for me?? I can''t get my hosting up and running yet and I
really need it up and running by today for my professor to check it off.
I only need it up for about two weeks. You will get a lot of karma
points for it :)
Thanks in advance!!
Jordan
--
Posted via http://www.ruby-forum.com/.
2006 Jul 07
1
Pessimistic Locking Plugin Breaks ActiveRecord::Base.count()
After installing the PessimisticLocking plugin I noticed that
ActiveRecord''s count method no longer works (see below). If I remove
the plugin it resolves the problem.
I need both. Any ideas?
I have also read that Pessimistic Locking is now baked into ActiveRecord
in Edge Rails. I have tried Rails 1.1.2 and 1.1.4 and that doesn''t seem
to be the case. Any idea when
2006 Jun 17
1
Quick Question: Random item from array
Well I think this is a quick question. I would like to select a random
item from an array. I''m thinking maybe I need to generate a random
number from 0 to array length. Actually I''m not exactly sure how to do
this since I can''t seem to find math.random/math.floor on ruby api?
Knowing ruby, there is probably a much easier way to do what I am trying
to do. Any
2009 Oct 13
2
Single Table Inheritance (STI) Broken: NameError
Some how I''m getting NameError: uninitialized constant when accessing a
child models that inherits form the parent model. However, if I access
the parent model first, then the child model is resolved.
What am I doing wrong? My steps are below...
Thanks,
Francis.
> ./script/generate model Blah type:string
class CreateBlahs < ActiveRecord::Migration
def self.up
create_table
2010 Feb 19
2
Problem with assert_redirected_to
I have taken over some old Rails code and am trying to get the tests to run.
In the functional test every time the assertion ''assert_redirected_to'' is
called I get the following error:
test_should_update_venue(VenuesControllerTest):
NoMethodError: undefined method `[]'' for
#<Enumerable::Enumerator:0x102f747e0>
2006 Feb 01
4
exclude a column in save!
Hi all,
I have a column that peeks its value from a sequence (postgres) some
times. Other times, I set it to a certain value.
This column has a default value of "nextval(''the_sequence'')"... When I
want that this column peeks the value from the sequence, I do this:
obj = Mymodel.new
obj.some_column1 = blah
obj.some_column2 = blah
obj.some_column3 = blah
obj.save!
but
2005 Feb 12
3
ActiveRecord not updating record
Hi,
I''m having some problems using ActiveRecord to update records in a
sqlite database. This isn''t exactly as rails question, since I''m
doing this initial import outside of rails, but I''m hoping someone
hear might have an idea as to what my problem is.
The basic problem is with the following code (which is run in a big loop)
m = Movie.find_by_title_and_year
2006 Jul 15
2
Render -> ActionController -> Render -> ...
Hi Guys,
ActiveRecord is great for being able to drill down through many tables.
I often locate the very "top" record, and have a render :action =>
"show" display that top record.
Often I want to drill down like:
@kingdom.phylums.classes.orders.each do |order|
render :partial => "order/show"
end
But, depending on the user who is logged in, they see a
2006 Nov 19
1
How to create a SQL query without ActiveRecord?
I want to write an independent (not model-related) SQL query for some
statistic information
in an online shop system. So I know I could grab all users with
ActiveRecord and then just
count the array size, but that would massively waste resources. And I
also want MySQL to do
some max, min and average calculations. So is there a way to issue a
query and get the result set
without models being
2006 Jun 30
2
Help with translating an object model to a relational mode
Hello rails friends,
I am writing a soap interface to a databse for a .Net guy in rails.
Actionwebservice kicks ass, however, I need some help translating the
object model to a relational one:
class Customer{
string firstName
#blah
string[] email_addresses
PurchaseHistory[] myPurchases
}
class PurchaseHistory{
#blah blah blah
}
The object model is non-negotiable. I am not
2006 Mar 23
8
ActiveRecord & Prepared Statement
I searched the archives and found a thread about it, but I didn''t
understand: are prepared statement used by ActiveRecord on those
databases that could handle them (Postgresql, Mysql, Oracle etc)?
In case they are not used, are they planned? Is there a roadmap about
Rails I can find somewhere?