I have created a new table including a column "note". The default is varchar(255) I believe but I wish to have this column be a text area vs. a field and to allow more data. I imagine that I would make this change in ActiveRecord::Migration file but I am curious as to the format. Do I simply change the varchar(255) to varchar(1000) for e...
Running a Ruby on Rails (RoR) app or Ruby code which uses the ActiveRecord framework, you get the error message:
Please install the postgresql adapter:
gem install
activerecord-postgresql-adapter
Trying to run:
gem install activerecord-postgresql-adapter
also fails, leaving you at a loss.
...
Hello,
I'm using the 'binarylogic-searchlogic' gem in version 2.3.5 along with Rails 2.3.4.
What I want to do is performing a search on a model for a specified value over multiple attributes. I achieve this through chaining everything together like
User.first_name_or_last_name_or_email_like(value)
But with more and more attributes ...
Hi all,
i am trying to insert into multiple tables using rails..
i have a table called users and services.
when i create a user the user details should go into users and a service name and userid should go into services table.
Any help would be greatly appriciated.
Thanks.
...
When you do Something.find(array_of_ids) in Rails, the order of the resulting array does not depend on the order of array_of_ids.
Is there any way to do the find and preserve the order?
ATM I manually sort the records based on order of IDs, but that is kind of lame.
UPD: if it's possible to specify the order using the :order param an...
I have a model that uses the low level validate_on_create method, based on a simple condition I'm adding an error message to the field, e.g
self.errors.add(:expiry_date, "is too soon") if self.expiry_date && self.expiry_date < Date.today + 1.week
When rendering the view 'new' after a failed save the field isn't picked up by error_mess...
Folks,
Want to make sure I understand this correctly. And please disregard the case for inheritance here (SentientBeing), trying to instead focus on polymorphic models in has_many :through relationships. That said, consider the following...
class Widget < ActiveRecord::Base
has_many :widget_groupings
has_many :people, :through => ...
Hi everybody: let me do a bit of "concept mining" here: I am involved in mantaining/extending an application whose functionality is distributed across several servers. For example, we have a machine running the ApplicationServer, another running the DataServer and so on.
This application has a Web Interface. The current UI is totally im...
I have an aggregated attribute which I want to be able ask about its _changed? ness, etc.
composed_of :range,
:class_name => 'Range',
:mapping => [ %w(range_begin begin), %w(range_end end)],
:allow_nil => true
If I use the aggregation:
foo.range = 1..10
This is what I get:
foo.range ...
I am writing a migration generator for a plugin I am writing and I need to to be able to find what unique indexes a table has so I can modify existing unique indexes to become a composite unique index. I have been trying to find a way to access what indexes a table has with ActiveRecord. I have only been able to find ActiveRecord::Conn...
Hi how to build a named_scope which will be common for all models.
...
Following are the 1-to-M models:
class FotoGossip < ActiveRecord::Base
has_many :uploads
attr_accessible :published_at, ...
end
class Upload < ActiveRecord::Base
belongs_to :foto_gossip
end
Now I want the Uploads.all with the condition :published_at NOT NULL of the corresponding upload's parent model?
...
How to do that with ActiveRecord? My code:
p = Product.create
l = Label.create
p.labels.add << l
But I get l.parent == nil
create_table "labels", :force => true do |t|
t.integer "product_id"
end
...
In a recent discussion on ORMs for webapps someone mentioned that there are times you don't want to have IdentityMaps for webapps. I don't understand this, because it seems as though in the context of a singular request to the app, you would want all work on records to be consistent. This means if I "look" at an object A which references...
If my models look like this:
(app/models/letter.rb)
class Letter < ActiveRecord::Base
def cyrilic_equivilent
# return somethign similar
end
end
class A < Letter
end
class B < Letter
end
Can my migrations also follow this pattern:
class CreateLetter < ActiveRecord::Migration
def self.up
create_table :letters do |t|
...
I have the following entry in my database:
t.time :my_time_stamp
In my controller I update it like this:
model.update_attributes(:my_time_stamp => Time.now.utc)
I can see that I'm writing:
Mon 9 November, 8:54.54 UTC 2009
However, when I later read this value I get:
Sat Jan 01 08:54:54 UTC 2000
It seems that the time part has...
Hi.
I have a standard active record model with an attributes that is required:
class Sample < ActiveRecord::Base
has_many :colors
before_validation :grab_colors
validates_presence_of :size
validate :number_of_colors
private
def grab_colors
# grab x number of colors | x = size
end
def number_of_colors
self...
I have a these 3 models:
class User < ActiveRecord::Base
has_many :permissions, :dependent => :destroy
has_many :roles, :through => :permissions
end
class Permission < ActiveRecord::Base
belongs_to :role
belongs_to :user
end
class Role < ActiveRecord::Base
has_many :permissions, :dependent => :destroy
has_many :users, :thro...
Kind of hard to explain but I'm going to try: I have a model called Message, which represents a request for an email to be sent out, a model called Segment which is pulled from a third-party application using a MySQL view (and is read-only), and finally a User model. Segment and message both belong to a user.
The problem is that I nee...
In my rails app I have two models that are related by has_and_belongs_to_many. This means there is a join table.
Imagine the scenario where I am adding users to a game. If I want to add a user, I do:
@game.users << @user
Supposing that I want to know in what order I added these users. I can do this:
@game.users.each do....
My qu...