Displaying 20 results from an estimated 400 matches similar to: "Saving an ActiveRecord object"
2016 Oct 28
2
Encontrar la primera columna no NA
Hola a todos, me ha gustado mucho la solución de Carlos, muy eficiente y
muy ingeniosa al utilizar la funcion col() que o no la conocia o no me
acordaba de ella.
La parte mas "lenta" sigue siendo el apply que en el fondo no es mas que un
ciclo for a traves de las filas, asi que inspirado por el metodo de Carlos
pense que podria ser mas rapido si iteramos a traves de las columnas por lo
2016 Oct 27
4
Encontrar la primera columna no NA
Por último, utilizando la indexación lineal de matriz que propusó luisfo en su momento:
> t <- Sys.time()
> M=as.matrix(dat)
> index <- which(!is.na(M)) - 1
> meses<-colnames(M)
> M2<- data.table(columna=index %/% nrow(M) +1L, jugador=index %% nrow(M) +1L , valor=M[index+1L])
> setkey(M2,jugador,columna)
>
2016 Oct 27
2
Encontrar la primera columna no NA
Otra solución algo más rapida:
> t <- Sys.time()
> dat[,jugador:=1:.N]
> dat2=melt(dat,id.vars="jugador")
> setkey(dat2,jugador)
> dat2[,index:=min(which(!is.na(value))),by=jugador]
> dat2[,.(First_month=variable[index[1]],Value_First_month=value[index[1]]),by=jugador]
jugador First_month Value_First_month
1: 1 Uno 0.93520715
2:
2008 Sep 17
0
permalink_fu and classes with different primary_key than id?
Has anyone else had problems with this scenario?
class Team < ActiveRecord::Base
# Primary key
self.primary_key = ''team_id''
has_many :players, :foreign_key => :team_id
has_permalink :city, :param => true
end
I am getting all kinds of trouble - that goes away if I comment out
the has_permalink declaration.
With PermalinkFu:
>> fs = Team.new
=>
2010 Jan 25
0
has_many, :finder_sql, setting attributes
Hi all,
My question is somewhat complicated, but bear with me. My project has a
number of models: User, Program, and Team. Users belong to multiple
Programs. Programs have multiple teams, but Teams belong to one
program. For each Program a User belongs to, he can belong to multiple
Teams. (Think of this in an athletic context where users are athletes,
programs are universities). So my
2006 Aug 14
2
Another try with REST
I''m using edge rails.
My routes.rb is:
map.connect '':controller/service.wsdl'', :action => ''wsdl''
# Install the default route as the lowest priority.
map.connect '':controller/:action/:id''
map.resources :team <---- THIS LINE ADDED BY ME
Also have a team_controller.rb, a team.rb model and scaffolding for it.
If I
2006 Mar 09
1
Howto save / update using multiple tables?
# Controller
def create
@person = Person.new(params[:person])
@address = Address.new(params[:address])
...
end
If a person has an address, how can I save some data into 2 different
tables?
Can I do the following?
@person.address = @address
if @person.save
render ...
else
render_text "Error"
end
Or do I have to use:
if @person.save
if @address.save
render ...
else
2006 Jan 31
1
Updating :has_many - :through related items
Hi,
I''ve got my little app working pretty well. I''m using pretty much the
model and table layout from my previous thread, as suggested by Bill
Katz:
<http://www.ruby-forum.com/topic/52506#26260>
I have the Create page working and a delete Match page working, which
along with the appropriate record in the Matches table, removes the
linked items in the competitions table.
2006 Jan 17
0
URL to method?
Do I need to edit routes.rb to get the following behavior?
URL ==> method (source)
/admin ==> AdminController#index (/controllers/admin_controller.rb)
/admin/teams/list ==> Admin::TeamController#list (/controllers/admin/team_controller.rb)
/admin/teams/edit/1 ==> Admin::TeamController#edit(:id => 1) (/controllers/admin/team_controller.rb)
And will it wreck havoc with my
2006 Apr 03
2
HABTM migrations
Bad rails day for Matt-
In a migration, for a habtm:
create_table :teams_users do |t|
t.column :team_id, :integer
t.column :user_id, :integer
end
Ok, fine. In a controller (well really a migration script):
@user.teams << Team.find( 3 )
And the SQL pumped at my server is:
INSERT INTO teams_users (`team_id`, `id`, `user_id`) VALUES (3, 3, 34)
Which
2009 Jul 29
5
[newbie] double relationships in database
I have the following tables
teams
id :string
name :string
and
matches
id:
home_team :team_id
visitor_team :team_id
how can I reflect that kind of relationship in a RoR model?
thanks and keep up the good work.
2008 Dec 20
9
Upgrade to Rails 2 - problem with "save" (MySQL boolean issue?)
I have been working through an upgrade of my 1.2.6 application to
2.2.2.
I am almost there but I have hit a problem with ActiveRecord.
Before the upgrade, the following code was working fine.
def create_root(administrator)
root = create_root_collection(self.pingee_name,
administrator,
2008 Feb 25
1
NoMethodError: undefined method `<=>' for :zip:Symbol
Long time programmer, but I just started learning RoR last week. I am
going through some examples in the book "Ruby on Rails: Up and
Running".
The example I am on had me add a table to the database that looks like
so:
CREATE TABLE people (
`id` int(11) NOT NULL auto_increment,
`type` varchar(20) default NULL,
`name` varchar(20) default NULL,
`email` varchar(30) default NULL,
2006 Jul 26
8
team captain - habtm w/has_one...
the below...
class User < ActiveRecord::Base
has_and_belongs_to_many :teams
class Team < ActiveRecord::Base
has_and_belongs_to_many :users
has_one :captain, :class_name => ''User''
produces the error...
Mysql::Error: Unknown column ''users.team_id'' in ''where clause'': SELECT *
FROM users WHERE (users.team_id = 1) LIMIT 1
i
2016 Oct 27
3
Encontrar la primera columna no NA
Imaginemos que tenemos una matriz con datos temporales por sujetos.
Pongamos que numero de veces que ha jugado una carta en un juego online. Y
que quiero saber cuantas veces jugo la carta el primer mes que estuvo en el
juego.
Pero claro mi matriz guarda los datos temporalmente de tal manera que:
# data.table( Enero = c( 1, 4, NA , NA , NA) , Febrero = c( 2, 6, 1, NA, NA
) , Marzo = c( 8,6,7,3,
2016 Jan 18
3
Extraccion de datos de una Web
Buenas tardes,
Quiero extraer datos de una web en la que ser relaciona la semana con
la puntuación obtenida por un jugador. Ahora mismo llego a obtener
elnodo en el que se relacionan la semana con la puntuación obtenida,
pero no soy capaz de extraer esa informacion en una tabla de dos
columna (semana, puntuacion) teniendo en cuenta que puede que haya
semanas que no haya puntuado (en el ejemplo,
2009 Jun 25
7
Join Tables
I just have a few questions about join tables. From my understanding
the following applies (correct me if I''m wrong):
1.Join tables are always named with the names of the two associated
tables, in alphabetical order, separated by an underscore.
2.The foreign key fields are named with the name of the table they are
referencing, with _id appended.
3.The foreign key is referencing a
2008 Jan 27
4
(REST) Nested routes
Hello, I''m in troubles with nested routes. I have three models: Team,
Tournament and TeamTournaments
class Team < ActiveRecord::Base
has_many :tournaments, :through => :team_tournaments
has_many :team_tournaments
class TeamTournament < ActiveRecord::Base
belongs_to :team, :foreign_key => ''team_id''
belongs_to :tournament, :class_name =>
2016 Jan 19
2
Extraccion de datos de una Web
Muchas gracias a ambos!!!! Las dos soluciones me han funcionado.
Un saludo.
El día 18 de enero de 2016, 18:35, Carlos Ortega
<cof en qualityexcellence.es> escribió:
> Hola,
>
> Pero, si ya casi lo tienes... te quedan un par de pasos y ya está...
>
> Simplemente tienes que transformar "puntos_nodo" a bien un data.frame aunque
> quedará lleno de cosas que no te
2006 Jun 22
4
Filter on variable
Hi all,
I have a question about filtering on a variable.
If I have the following code in my controller to select a list of
users
> @allusers = User.find(:all,
> :conditions => [''team_id = ?'', @params["id"],
> :order => ''created_at'')
Is there an easy way to find out all users who