Displaying 20 results from an estimated 300 matches similar to: "Rails3-default_scope throws exception: undefined method abstract_class? for Object:Class"
2013 Jun 15
1
A puzzle about default_scope
Hi, guys
I have a puzzle about default_scope.
Suppose I have two model:
class User < ActiveRecord::Base
has_many :blogs
default_scope where(deleted_at: nil)
end
class Blog < ActiveRecord::Base
belongs_to :user
end
I want to produce sqlselect blogs.* from blogs inner join users on users.id
= blogs.user_id and users.deleted_at is null
And the code Blog.joins(:user), which I think
2009 Jul 11
2
offeride :limit named_scope default_scope
Hi,
Rails 2.3.2
class TestD < ActiveRecord::Base
default_scope :limit => 12
named_scope :limit, lambda { |num| { :limit => num} }
end
ruby script/console
>> TestD.all
TestD Load (0.7ms) SELECT * FROM "test_ds" LIMIT 12
=> []
>> TestD.limit(14)
TestD Load (0.3ms) SELECT * FROM "test_ds" LIMIT 12
=> []
Any ideas why the default limit
2011 Feb 02
6
how to set default_scope for the whole application?
I know I can set default_scope for individual active record model, but
can I set one up for the whole application?
thanks
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
2008 Feb 21
1
polymorphic has_many from ActiveRecord::Base????
I have a polymorphic thingy called fields and I need to on each and
every model, so I''d like to do the has_many from the base class, like
this...
ActiveRecord::Base.class_eval do
has_many :fields, :as => :model, :dependent => true
end
It fails with this no method error (class_of_active_record_descendant)
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/
2009 Oct 17
2
Skip default_scope when running migrations
Hi,
I was wondering if there is a way to skip the application of a
named_scope to calls made in legacy migrations. I am working with some
old migrations that include some data manipulation tasks, and my default
scope is preventing those migrations from running. I''m trying to avoid
editing those migration files with with_exclusive_scope.
Thanks,
-G
--
Posted via
2006 Aug 24
0
Model with self.abstract_class=true allows save method call
I think this is a bug.
I declared a model with self.abstract_class = true and then tried to
call save on it and it attempted the save. I think this should raise a
"method not allowed" exception of some sort.
Where is the Trac system that I would use to report this?
Thanks,
Wes
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You
2008 Jan 08
1
add comments to ALL models (ie automatically add has_many)
I have the acts_as_commentable and a bunch of others added to pretty
much every model, is there a way to automaically add these to EVERY
model ?
I tried the following but it fails with an error...
ActiveRecord::Base.class_eval do
has_many :notes, :as => :model_with_notes, :dependent => true
end
fails with....
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/
2007 Oct 12
6
abstract_class... what exactly does it do
Hi,
Does anyone know much about abstract_class? Does it actually prevent
instances of the class from being created? Does it disable certain
methods? I already know what it''s for, but I want to know what setting
self.abstract_class=true actually does.
The reason I ask is that I want to use it for a slightly unorthodox
purpose. I want a class who''s only attributes are its
2013 Apr 08
1
cattr_accessor and Thread.current prblems
Hello,
I am trying to convert three applications to multitenant, all of them have
same structure difference is only in little functions and template designs.
All of them using cattr_accessor for setting currencies and other data, and
it works perfectly
Now i added app_id as cattr_accessor to App model to use it in
default_scope to implement multi-tenancy
class App < ActiveRecord::Base
2011 Sep 15
1
bypass defualt scope.
class Shop < ActiveRecord::Base
has_many :documents, :dependent => :restrict
end
class Document < ActiveRecord::Base
belongs_to :shop
default_scope :order => ''updated_at DESC''
end
in the Shop show view I have:
- for document in @shop.documents
%li(id="shop_documents")= link_to document.subject,
shop_document_url(@shop, document)
I want list
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
2009 Jul 23
11
Problem with named_scope
Here are my scopes:
default_scope :order => ''posted_on DESC'', :conditions => { :status =>
''visible'' }
named_scope :positive, :conditions => { :rating => ''positive'', :status
=> ''visible'' }
named_scope :neutral, :conditions => { :rating => ''neutral'', :status
=>
2010 Jul 04
1
Rails 3: ActiveRecord .include not working
Really no idea what''s up...
class Auction < ActiveRecord::Base
has_and_belongs_to_many :categories
end
class Category < ActiveRecord::Base
has_and_belongs_to_many :auctions
default_scope order(''title'')
scope :active, where(:active => true)
end
class CategoriesController < ApplicationController
respond_to :html, :json
# GET /categories/:id
2011 Aug 01
0
ActiveRecord:: DangerousAttributeError only in console
Good afternoon,
I am currently migrating an app from rails 2.1 to rails 3 and found a
problem that I realized was due to the fact that the BD columns had
reserved rails names.
I only have read access to BD, so I can''t change the name of columns.
The column in question is called "reference" and I''m having a
very strange behavior during implementation:
1) initializing /
2012 Apr 17
0
Request for adding an "alias"/"as" to ActiveRecord
I often find myself in situations where I''m fighting against
ActiveRecord because there is no easy way to alias some tables.
For example, I''m converting a legacy application. So, there is a
''condition_type'' table that actually should be something like ''fields''.
Also it can have a parent field and deletion is handled by setting a
2012 Jun 21
1
ActiveModel::Serializers::JSON support arbitrary keys
Is there a reason why AM:S doesn''t support arbitrary keys to serialization?
I can see a lot of uses cases where arbitrary keys could come handy. Right
now, if one tries to do it, AM:S checks if the keys match a method of the
model and raises exception if it can''t find any.
class Client < ActiveRecordBase
attr_accessible :name, :address, as: :creator
include
2007 Nov 15
4
Using .find_by_sql for database/admin queries
I want to create an internal admin view to display the output of "show
variables" from mysql. What''s the best approach do this?
For example, I''m doing something like this:
@variables = ActiveRecord::Base.find_by_sql "show variables;"
Then, I get stuff like this back (227 elements in @variables) in
script/console:
>> @variables[0]
=>
2011 Jul 11
2
Can't get this Rspec test to pass
Hello,
I''m completely new to Rspec testing and I''m finding it very difficult to
mock specific objects.
In this test, I have a before block setup as such:
[code]
before do
setup_controller_for_warden
controller.session[:operation_id] = 1
@operator = Factory :operator
sign_in :operator, @operator
@persist_herd = Herd.new
2010 Dec 30
3
rake db:seed with has_many through (m:n with seperate table)
My model consists of users and tasks (m:n), the relation is stored in a
seperate table sharedtabs (that contains some extra fields).
Between tabs and tasks there is a 1:n relation.
I have trouble writing my seed.rb:
works: (1)
tab = Tab.create(:name => ''Admin'', :category => 0)
tab.tasks.create(:name => ''Admin_Tab1_Private Task 1'')
works: (2)
2010 Sep 17
6
Rails base model
I''m very new to Ruby and to Rails. I''m coming from PHP and CakePHP.
I would like to create a base model from which all other models will
inherit from.
I have done this:
class AppModel < ActiveRecord::Base
end
and
class Post < AppModel
end
I''m getting the following error:
Table ''blog_development.app_models'' doesn''t exist
My