Displaying 20 results from an estimated 300 matches similar to: "Create! Syntax"
2006 Jul 12
1
When to use Mutex::synchronize?
I have a simple question when to the synchronize method in the Mutex
class.
Now that backgroundrb has allow_concurrency = true there is no need
to synchronize database calls in threads.
The question I have is lets say I have a simple method in my worker
as follows:
def some_method
SomeModel.find_all each do |obj|
obj.some_count += 1
obj.save!
end
end
It accesses the database, but
2008 Mar 03
1
Rspec and plugins
I have a question regarding best practices around module and plugin
testing for rails applications. In our application we have created
several plugins that extend ActiveRecord::Base with class methods,
that when invoked in a model add behavior to that model. For
example ...
class SomeModel < ActiveRecord::Base
adds_some_cool_behavior
adds_another_wicked_sweet_behavior
end
My
2006 Feb 07
4
Ruby, Rails & Inheritance
Hi!
I am looking for a solution for the following problem:
Some of my models share some attributes and also was in need for some
extra features, so I created a class "RecordWithFeatures":
-----------------------------------------------------------------
class RecordWithFeatures < ActiveRecord::Base
# @Override
def self.descends_from_active_record?
superclass ==
2006 Feb 16
10
Ruby class variables and access from view templates
I have an app that requires me to define a class variable (actually an
array) in a controller and then access it from within a view. It seems
that the class variables aren''t working right. Here is an example of
what I''m trying to do.
class DisplayController < ApplicationController
@@thumbnail_array = Array.new
...
def some_method
@@thumbnail_array = SomeModel.find_all
2006 Jun 05
2
Simple Rake question
Newbie question but here goes:
Isn''t rake supposed to automatically search the lib/tasks subdirectory for Rake files/tasks?
I have a task called "do_this.rake" in file foo.rake in lib/tasks/rails - how do I invoke it from the command line in the root directory of my Rails application?
Presuming I have a file called "Rakefile" in the root directory of my Rails
2006 Feb 15
2
extending rails via /lib - problems
I wanted to group some functions which I use in some models in one
place. Controllers have application.rb and views have helpers but I
couldn''t find anything about models. Using the /lib directory seemed to
be the only way.
Alright... so I have something like this:
/lib/code.rb
class ActiveRecord::Base
def method_a(n)
.......
end
def method_b(n)
........
end
end
2010 Aug 25
4
degree C symbol in a function
Hello help,
I have changed around some graphing code and made it into a function.
Previously they y label of the axis was inserted as text in its own
layout box.
text(1,1, expression(~degree~C),cex=1)
This worked great and resulted in the symbol for degree.
In the function, I have changed it so:
text(1,1,paste(b_unit),cex=1)
and
b_unit<-expression(~degree~C)
This now inserts ~degree~C
2012 Jun 07
3
conditional statement to replace values in dataframe with NA
Hello and thanks for helping.
#some data
L3 <- LETTERS[1:3]
dat1 <- data.frame(cbind(x=1, y=rep(1:3,2), fac=sample(L3, 6, replace=TRUE)))
#When x==1 and y==1 I want to replace the 1 values with NA
#I can select the rows I want:
dat2<-subset(dat1,x==1 & y==1)
#replace the 1 with NA
dat2$x<-rep(NA,nrow(dat2)
dat2$y<-rep(NA,nrow(dat2)
#select the other rows and rbind
2010 Oct 26
4
divide column in a dataframe based on a character
Hello,
If I have a dataframe:
example(data.frame)
zz<-c("aa_bb","bb_cc","cc_dd","dd_ee","ee_ff","ff_gg","gg_hh","ii_jj","jj_kk","kk_ll")
ddd <- cbind(dd, group = zz)
and I want to divide the column named group by the "_", how would I do this?
so instead of the first row being
x
2010 Dec 01
5
Pass an operator to function
Hi guys,
How to pass an operator to a function. For example,
test <- function(a, ">", b)
{
return(a>b) #the operator is passed as an argument
}
Thanks,
--
View this message in context: http://r.789695.n4.nabble.com/Pass-an-operator-to-function-tp3066627p3066627.html
Sent from the R help mailing list archive at Nabble.com.
2006 Jan 11
2
How to execute an SQL statement in rails?
Hello,
This is probably a silly question but looking at
"api.rubyonrails.org", I can''t seem to figure out which method I
should be using ... I want to execute an sql statement, like "truncate
table BLAH" from within one of my rails app ... What''s the "right" way
to do this?
Thanks,
/B
--
Bruno Mattarollo <bruno.mattarollo@gmail.com>
2006 Jul 05
10
Scalable alternative to #find_all
Is there any scalable alternative to iterating all the records of a
certain model? #find_all seems to load everything into memory. With
500.000 records it will be a swap storm.
Pedro.
2010 May 18
1
issues with R Library on a Server
Hello,
I am a bit over my head on this issue. My colleagues and I are running
R off of our server. We all have admin rights and prior to yesterday
we all had our own libraries. Our main system administrator advised us
that we should have a shared library. So, I am trying to do this.
I have downloaded the latest version of R and installed it on the
main drive of our server in the "Program
2011 Jan 27
2
identifying when one element of a row has a positive number
Hello,
I am not sure where to begin with this problem or what to search for
in r-help. I just don't know what to call this.
If I have 5 columns, the first 2 are the x,y, locations and the last
three are variables about those locations.
x<-seq(1860,1950,by=10)
y<-seq(-290,-200,by=10)
ANN<-c(3,0,0,0,1,0,1,1,0,0)
CTA<-c(0,1,0,0,0,0,1,0,0,2)
GLM<-c(0,0,2,0,0,0,0,1,0,0)
2013 Jul 23
2
downloading web content
Hello,
I am trying to use R to download a bunch of .csv files such as:
http://biocache.ala.org.au/ws/occurrences/download?q=Banksia+ericifolia
I have tried the following and neither work:
a<- getURL("
http://biocache.ala.org.au/ws/occurrences/download?q=Banksia+ericifolia")
Error in curlPerform(curl = curl, .opts = opts, .encoding = .encoding) :
embedded nul in string:
and
2011 Jan 26
4
question about records count.
Hi. I have few models - user, task, file
class User < ActiveRecord::Base
has_many :tasks
end
class Task < ActiveRecord::Base
belongs_to :user
has_and_belongs_to_many :files
end
class File < ActiveRecord::Base
has_and_belongs_to_many :tasks
end
I want to know files count for some user. is there some ''right'' way to
do it without getting all tasks and looping
2010 Apr 19
2
selecting rows based on number that occurs after letter
Hello,
I am trying to cycle through a csv and make some summary statistics.
I need to select rows based on the number in the row name that comes
after the letter 'y'. For example, ? BA1y1 would equal 1, ?C3A2r3y1
would equal 1 and ?MA3r3y1r3 would equal 1.
I currently have my code ?cycling through by the 5th character but my
rows have variable length and the y can occur in several
2006 Jun 26
1
Separate Read and Write Database
Hello,
I need to access an mirrored database with one read and one write
cluster. Is there a way to tell a model to use two connections? So that
all updates etc go to the write database and all read from the read one?
This is a fixed set up I can not use MySQL 5.x stuff and additionally i
get a token on write, which can be checked on read (and wait for
replication) if new data is needed.
I
2008 Jun 04
2
Handling exceptions
Is there a convention for handling exceptions within BackgrounDRb workers?
For example, I have a worker which does some asynchronous data processing
(*not* a scheduled worker) based on some things in the database. However,
if an exception is raised within that worker, then the process for that
worker is killed off. Ideally I would want that worker to just silently
fail and be optimistic that it
2010 Aug 30
5
Rails 3.0 API doesn't do word-wrap
Hi Guys,
I just realize that on the API documentation the code snippet is overflowing off the screen. Is this an intended behavior? Or who should I contact to get this one fixed.
You can see the screenshot here: http://skitch.com/sikachu/dw82n/screen-shot-2553-08-30-at-16.24.26
Thanks :)
Prem Sichanugrist
--
You received this message because you are subscribed to the Google Groups "Ruby