Displaying 13 results from an estimated 13 matches for "increment_counter".
2006 Apr 18
1
what happened to my increment_counter method?
...iting my little app and now
it doesn''t work.
here''s my models:
class Company < ActiveRecord::Base
has_many :people
end
class Person < ActiveRecord::Base
belongs_to :Company, :counter_cache => true
end
then i go into my console and say:
c = Company.find(:first)
c.increment_counter
and its all like "waaaaaaH"
NoMethodError: undefined method `increment_counter'' for #<Company:
0x259e3b0>
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.2/
lib/active_record/base.rb:1792:in `method_missing''
from (irb):8
if i type:
C...
2006 Oct 25
1
how to use increment_counter in model
...ontroller function:
>>>
def feed
@chriss_monster = ChrissMonster.find(params[:id])
@chriss_monster.feed
redirect_to :action => ''list''
end
<<<
Here''s my model:
>>>
class ChrissMonster < ActiveRecord::Base
def feed
ChrissMonster.increment_counter :eat, :id
end
end
<<<
When I call the controller function, it directs me back to the list
page, it doesn''t give me an error, and it does NOT increment the "eat"
value.
What am I doing wrong??
Thanks for reading.
--Dan W.
--
Posted via http://www.ruby-forum.com/...
2006 Jan 03
4
Would someone like to tell me why this code will not solve my problem? (it''s short)
I am building an invoicing system but cannot use the auto_increment
field to determine the invoice number (because they are running 3
different companies off the one system. I need to find the last
invoice number from any given company and then add 1 to it to get the
next invoice number. BUT, there is a unique case on the very first
invoice produced because there is no earlier invoice
2009 Jun 01
4
counter_cache is making a redundant SELECT before UPDATE
Hi,
I have the following code:
Message, belongs_to :topic, :counter_cache => true
topic = Topic.find_from_permalink(params[:id])
topic.messages.create(params[:message])
When the message gets created, then AR issues a supplemental SELECT to
retrieve the message''s topic and then updates its messages_count. Why is
that happening?
If I do it manually:
if
2007 May 14
3
Counter Problem
Hi. I have a problem with counters in Rails. The situation looks like
this:
-3 simple models
class Forum < ActiveRecord::Base
has_many :posts
end
class Topic < ActiveRecord::Base
has_many :posts
end
class Post < ActiveRecord::Base
belongs_to :topic, :counter_cache => true
belongs_to :forum, :counter_cache => true
end
- In migrations i have declared
t.column :posts_count,
2009 Sep 07
11
autoincrement for non-id column
There is a table:
execute (<<-SQL)
CREATE TABLE "tasks" (
"id" serial primary key,
"number" serial,
"version" integer DEFAULT 0 NOT NULL,
"latest_version" boolean DEFAULT ''t'' NOT NULL,
"hidden" boolean DEFAULT ''f'' NOT NULL,
"type" character varying (1) NOT
2007 Nov 14
7
BackgrounDRb version 1.0RC1 available now
...new code base. The answer is yes, but
again, changes would be required. "progress bar" example would look
like this:
class ProgressWorker < BackgrounDRb::MetaWorker
set_worker_name :progress_worker
def create
@counter = 0
add_peridic_timer(2) { increment_counter }
end
def increment_counter
@counter += 1
register_status(@counter)
end
end
And using MiddleMan proxy, you can keep queering status of your progress bar:
MiddleMan.ask_status(:worker => :progress_worker)
I would welcome, anyone who cont...
2013 Jan 20
20
ActiveRecord::Persistence.increment! requires a row lock to ensure isolated updates
The method is here:
https://github.com/rails/rails/blob/master/activerecord/lib/active_record/persistence.rb#L288.
The method takes the in-memory attribute value and increments it by the
specified amount. A safer approach (from an isolation standpoint) would be
to let the database determine the value. Instead of telling the database
what value to persist in the database, the SQL can written
2006 Mar 11
2
ActiveRecord increment confusion
Part of my application counts the number of times a link was clicked.
The Link.click function should increment the @link.clicks attribute.
I assumed
def click
@link = Link.find(params[:id])
if @link.increment(''clicks'')
redirect_to @link.url
else
flash[:error] = ''Could not update clicks''
redirect_to :action =>
2006 Feb 27
0
Better counter_caches
Hey everybody,
Rails currently offers ''belongs_to :counter_cache'', which is a very
basic replacement for count triggers:
":counter_cache - caches the number of belonging objects on the
associate class through use of increment_counter and decrement_counter.
The counter cache is incremented when an object of this class is created
and decremented when it?s destroyed. This requires that a column named
"#{table_name}_count" (such as comments_count for a belonging Comment
class) is used on the associate class (such as a...
2006 Jul 05
2
Serialized object behaves weird
Hi!
I got a class named EinsatzFilter which I serialized to session. Before
saving to session it works afterwards I keep getting the message:
"undefined method `to_s'' for #<Person:0x38c6ab8>". "Person" is a from
ActiveRecord::Base inherited class.
Code:
class EinsatzFilter
include ApplicationHelper
attr_reader :personen, :monat, :projekte, :kunde
2008 Jan 16
0
[CruiseControl] RubyOnRails build 8649 failed
...19:in `update''
./test/../lib/active_record/base.rb:685:in `update_all''
./test/../lib/active_record/base.rb:771:in `update_counters_without_lock''
./test/../lib/active_record/locking/optimistic.rb:139:in `update_counters''
./test/../lib/active_record/base.rb:790:in `increment_counter''
./test/../lib/active_record/callbacks.rb:309:in `callback''
./test/../lib/active_record/callbacks.rb:309:in `callback''
./test/../lib/active_record/callbacks.rb:304:in `each''
./test/../lib/active_record/callbacks.rb:304:in `callback''
./test/../lib/active_...
2006 Jul 24
7
[PATCH] Support for DB Clusters/Replication in ActiveRecord (RFC)
...ef count_by_sql(sql)
sql = sanitize_conditions(sql)
- connection.select_value(sql, "#{name} Count").to_i
+ connection(:read).select_value(sql, "#{name} Count").to_i
end
# Increments the specified counter by one. So <tt>DiscussionBoard.increment_counter("post_count",
@@ -725,7 +725,7 @@
# Returns an array of column objects for the table associated with this class.
def columns
unless @columns
- @columns = connection.columns(table_name, "#{name} Columns")
+ @columns = connection(:read).col...