Displaying 20 results from an estimated 4000 matches similar to: "Ruby class variables and access from view templates"
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
2006 Feb 18
5
Model methods and partial view templates
I have a method in a controller that invokes a
render :partial => ''some_partial_view''
In that view, I''m trying to access a method defined in a model, like
this;
<% for view in @an_array %>
<% local_var = view.some_method() %>
<% another_var = view.a_column_name %>
etc..
I am getting an undefined method error but the model is accessible
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
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.
2009 Oct 14
14
spec-ing private methods?
On Wed, Oct 14, 2009 at 5:49 PM, Scott Taylor <scott at railsnewbie.com> wrote:
>
> On Oct 14, 2009, at 3:36 PM, Joaquin Rivera Padron wrote:
>
> hello there,
> how do you tipically spec private methods? The thing is ? have something
> like this:
>
> def some_method
> ?? complex_method + other_complex_methods
> end
>
> private
> def complex_method...
2007 Apr 30
3
Slow performance
Hi folks.
I'm posting this to both the Fedora as well as the CentOS lists in
hopes that somewhere, someone can help me figure out what's going on. I
have a dual Xeon 3GHz server that's performing rather slow when it comes
to disk activities.
The machine is configured with a single 160 GiB OS drive (with
CentOS 5.0) and 4x500 GiB drives setup in a RAID-5 configuration.
2009 May 13
2
Object and Classes ?
I found a tutorial for creating classes using generic functions ? S3
way ! It was short description so I couldn't grok in full its
usage ... So far so good, what i currently do is something like this :
Blah <- function(data,...) UseMethod('Blah')
Blah.default <- function( ...... ) {
self = ....
class(self) <- 'Blah'
self
}
Blah.some_method <-
2009 Apr 08
4
Having trouble extending a class from a Rails plugin
I have class in a plugin that I want to crack open and add some
functionality to for a particular application. So, I created a file by
the same name as the class in my app/models folder and added some
methods to the class, but, I can''t seem to get Rails (2.2.2) to pick-up
the extended definition.
I did find while trying to debug the problem that if I paste the
extended definition into,
2006 Feb 20
3
Rewriting with an after_filter
All -
I''m completely new to RoR and also new to programming in an MVC
structure...
The Pragmatic Programmers guide to Rails says, temptingly:
"After filters can be used to modify the outbound response, changing the
headers and content if required. Some applications use this technique to
perform global replacements in the content generated by the controller?s
templates (for
2006 Jul 25
3
Question about how Mongrel process works with singletons
Hi,
I have a controller where I access a singleton class that I use to
connect to a DRbprocess
DrbConnector.instance.some_method
I notice that on every request, the constructor is called so it is
making a new instance of this singleton. Is this normal?
Thanks,
Curtis
2006 Jul 14
3
Accessing the Model class from Controller
Hi,
I wonder if there''s an easy way to access the associated Model class
from its Controller. Something that would allow me to write snippets
like the following:
class PeopleController < ApplicationController
def some_method
person_model_class =
self.some_method_to_retrieve_the_person_model_class()
end
end
Cheers,
Marco
--
Posted via
2012 Sep 04
5
Associations and Math between Models
I''ve setup two models, 1 and 2, that are associated by
has_and_belongs_to_many. I''m trying to get an attribute from model_1 to use
in a method in model_2. When I use the code below, I get an error saying
''undefined method model_1_id''. What am I missing? Thanks!
Model_2.rb
Class Model_2 < ActiveRecord::Base
...
has_and_belongs_to_many :model_1
def
2009 Aug 19
2
Create! Syntax
Hey All,
Two questions.
Firstly, what is the difference between create and create!
I see that create is document in the api
http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002269
What is the difference between the two of these functions and where is the
create! function defined.
Also,
What are the differences between these two calls?
a) SomeModel.create!{ :property_a =>
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 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 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 ==
2013 Jul 09
5
whenever gem
Hello All,
I want to schedule a mail every day.
I used whenever gem.
I added gem ''whenever'' in my gemfile. Then in the terminal I did -
"whenever ." which created a schedule.rb.
In schedule.rd I added this piece of code:-
set :environment, "development"
every 2.minutes do
runner "UserMailer.some_method"
end
Does it get invoked
2006 Apr 14
5
state_models plugin and file_column?
I was looking at Kyle Mawell''s extremely nifty-looking StateModels
plugin
http://www.kylemaxwell.com/articles/2006/02/06/fun-with-single-table-inheritance
and before I go down the road with it, I was wondering if anyone has
used it with file_column.
The way file_column deals with an uploaded file -- by storing it to the
filesystem in a path that employs the model name and id --
2006 Jul 19
1
Passing objects to drb, does it keep the existing db connection?
I have a simple question. Let''s say I do this in one of my models:
after_save
drb_conn.some_method(self)
end
When that object gets over to the background process is it the exact
same as?....
Model.find some_id #in the background process
As far as my background process is concerned passing the object is
not any different than passing the id and using the find method?
Because
2006 Jan 20
1
Best way to execute timed actions?
I''ve seen this come up a few times before on this list but never felt
it got a satisfactory answer. What is the best way to execute timed
actions? Examples include sending an email each week, calculating
interest each day, or cleaning up your database or server files.
This wiki page has some ideas, but these seem a bit extreme.