Displaying 20 results from an estimated 500 matches similar to: "aggregate / tranpose data"
2006 Jun 16
3
Does HABTM support non "id" FKs?
Quick question. Say I have a geographical database with counties and zip
codes where counties have and belong to many zip codes.
zip_codes (id, zip_code)
counties (id, name)
When I create the association table, the Rails way says to do the
following: counties_zip_codes (county_id, zip_code_id).
However, given that zip_codes.zip_code is itself a candidate key, I
would much prefer to do the
2010 Aug 19
1
Composite primary keys and :joins=>
I have a legacy db with the following simplified structure:
Table-A:
type_key, code_key, name, ... # PKs are type_key and code_key,
there is no id col and I cannot alter this db
Table-B: # each row has only the code as a foreign_key, the type_key
is hard-coded to "FOOKEY"
an_id, code, ...
Models:
class TableB < AR::Base
set_table_name ''table_b''
2006 Mar 21
2
Sorting by computed temporary field
Hey all,
I''m rather new to Ruby and Rails (and not great with SQL), but I''m
developing a ride sharing app and would like to be able to sort on
something I don''t have stored.
I have users, events, and rides, each of which has a zip code. Events
have_many rides, and rides belong_to events.
When an event is selected, I''d like to be able to show a list of
2009 Jun 23
2
syntax error, unexpected tINTEGER, expecting $end
Please help me solve the following error message:
syntax error, unexpected tINTEGER, expecting $end
I have this model:
Code:
1. class GeoDatum < ActiveRecord::Base
2. end
The database contains the table geo_data, which contains the zip_code
column, filled with zip codes. I get the above error when searching
for a zip code and the zip code exists in the table. Here is the
2006 Oct 13
3
Validation errors in has_one/belongs_to relationships.
I have two objects, QuoteInput and Insured.
QuoteInput has one Insured and Insured belongs to QuoteInput.
I don''t understand what I''m seeing.
I assign an Insured to a QuoteInput. The Insured object has invalid
data.
I call save! on the quote input. QuoteInput has no validations.
I expect two things to happen - 1) an exception should be thrown,
indicating that there was a
2013 Dec 10
2
form_tag + fields_for Rails 4
Hi There,
I''m trying to user fields_for inside a form_tag, but i can''t catch it
on my controller.
I just take some html code off to makes it easy to read
my view...
i''m using campuses_path(current_church, @campus) instead form_for
@campus, because my route is like
resources :campuses, :path => ":church/campuses"
<%= form_tag
2012 Mar 22
1
Rspec not loading fixtures
I am taking over a code base and am trying to run the tests. I am
somewhat new to RSpec so this might be a trivial problem.
Basically I can tell that the fixtures are not getting loaded. All 100
tests fail with a similar error.
But I don''t know why. Below is the code, with my narrative with ***
before it... Can you see anything or give me a clue where to look. So
far I am coming up
2009 Jul 31
2
Undefined method updated? for <model object>
Hi,
I have two model say-
ZipCode < ActiveRecord::Base
belongs_to :state_provinces
end
StateProvince < ActiveRecord::Base
has_many :zip_codes
end
if I do @zip_code.update_atribute(:city, "My City")
its giving Undefined method updated? for StateProvince
if I remove belongs_to specifier in ZipCode class then it work fine.
Any alternate solution??
Thanks
--
Regards,
Himanshu
2010 Jan 05
3
Tranpose and Aggregate Data
Hi,
I need to transpose and aggregate the 4th and 5th column of this data
set (below). The period is 1 to 100 years and some period has 1 entry
as shown in the example below.
Any ideas how to do this. Thanks in advance.
Noli
~~~~~~~~~~
From:
P_ID CROP Period Ini_Age Area_Cut
83 SORI 1 31 528.2465512
84 SORI 1 32 74.55179899
85 SORI 1 33
2012 Sep 28
1
How to Include Associations in #as_json
Hi,
Does anyone know how to include nested associations when overriding a
model''s #as_json method?
Below is my attempt to include direct and nested associations.
NOTE: "office" is a direct association, "company" is nested association
via "office". I''d like both included in the generated json output.
def as_json(options={})
super(:include
2006 Jun 16
0
Getting error on a group select
Hi,
I''m very new with Ruby and Rails. I have read Agile Web Development
with Rails and was trying to create a grouped selection list by
following his example on page 359.
My helper looks like this:
module LoginHelper
AssocOption = Struct.new(:code_name, :display_name)
class AssocType
attr_reader :type_name, :options
def initialize(name)
@type_name = name
2006 Jun 16
0
Getting an error on options_groups_from_collection_for_select
Hi,
I''m very new with Ruby and Rails. I have read Agile Web Development
with Rails and was trying to create a grouped selection list by
following his example on page 359.
My helper looks like this:
module LoginHelper
AssocOption = Struct.new(:code_name, :display_name)
class AssocType
attr_reader :type_name, :options
def initialize(name)
@type_name = name
2007 Nov 07
5
Unexplainable failure...at least for me
I have an address model with country_id and province_id fields
There is also a full_address method that returns an address that is in a
format that the google maps api will be able to return a long-lat
coords.
Within the full_address method there is a call to obtain the
province/state and country name.
---------
def full_address
...
full_address = [city, self.province.name,
2006 Dec 08
9
How to update partial attributes of a object from a form?
I have a user table, and it has forty columns, including name, gender,
address, email, phone...
So my @user object will have forty attributes.
I divide these attributes into 4 groups... namely ''general info'',
''personal info'', ''contact info''... and I make separate forms to edit
these 4 different group attributes.
The problem is when I update
2009 Apr 16
0
how to convert the find_by_sql code to the find code
I want to convert following query into pure ruby one i.e. by using find
@us_state_sales=SalesReport.find_by_sql("SELECT z.state,
sum(s.royalty_price) as royalty_price, sum(s.units) as units FROM
sales_reports s, zip_codes z
WHERE royalty_currency = ''USD'' && z.zip_code=s.postal_code GROUP BY
z.state ORDER BY royalty_price desc LIMIT 10")
i try something like
2010 Aug 11
2
Sweeping a zoo series
Given a long zoo matrix, the goal is to "sweep" out a statistic from the
entire length of the
sequences.
longzoomatrix<-zoo(matrix(rnorm(720),ncol=6),as.yearmon(outer(1900,seq(0,length=120)/12,"+")))
cnames<-c(12345,23456,34567,45678,56789,67890)
colnames(longzoomatrix)<-cnames
longzoomatrix[1:24,]
12345 23456 34567 45678
2006 Jan 10
1
Find last row (observation) for each combination of variables
Let's say I have a data.frame like
A B C TS other columns
1 1 1 12345
1 1 1 56789
1 2 1 23456
1 2 2 23457
2 4 7 23458
2 4 7 34567
2 4 7 45678
and I want the last row for each unique combination of A/B/C, where by "last" I mean greatest TS.
A B C TS other columns
1 1 1 56789
1 2 1 23456
1 2 2 23457
2 4 7 45678
I did this simply in SAS:
proc sort data=DF;
by A B C descending TS
2006 Apr 04
3
model validates twice in tests, produces duplicate errors
In my unit tests for my User model, I''m testing some validation cases.
What is really strange, and driving me crazy, is that in the unit
tests, it seems like the save method is causing my validations to
execute twice, and produce duplicate error messages. This is making my
tests fail (because I''m checking for the number of errors that I
expect). In the web browser, only one error
2006 Nov 07
1
reading VERY large binary files
Hello,
I am trying to read in elements out of a very large binary file ... the
total file is 4 gigs. I want to select rows out of the file, and the
current procedure I run works but is prohibitively slow (takes more than
a day to run and still won't complete). Is there any faster way to
accomplish this?
My current procedure looks like this:
readHH <- function(file_name,
2007 Nov 03
3
Birthdate validation
Hello everyone,
I''m almost cracking my head trying to do this birthdate validation. It
turns out that I can only accept users with at least 18 years old and
I''m trying to validate it writing this code on my user.rb fil at app/
models
class User < ActiveRecord::Base
validates_presence_of :full_name
validates_presence_of :street_address
validates_presence_of :city