I've got a simple active record validation on an object using this within a form:
form.error_messages({:message => '', :header_message => ''})
This in turn outputs something like "FieldName My Custom message"
What i need to do is remove the field name from the error message but leave my custom message.
Can anyone point me in the r...
I am try to find the top n number of categories as they relate to articles, there is a habtm relationship set up between the two. This is the SQL I want to execute, but am unsure of how to do this with ActiveRecord, aside from using the find_by_sql method. is there any way of doing this with ActiveRecord methods:
SELECT "categories".id,...
I would like to be able to gather all records in a table where the user_id is not null.
This is what I have but it doesn't seem to be working (even though I've had it working in a seperate project):
named_scope :all_registered, :conditions => ["user_id != ?", nil]
...
PROBLEM
Hello,
I am having no luck trying to break down this SQL statement into ActiveRecord/Rails friendly code and I'd like to learn how I can avoid a find_by_sql statement in this situation.
Scenario
I have users that create audits when they perform an action. Each audit is of a specific audit_activity. Each audit_activity is wort...
i would like to have your opinion in a project i am currently working on.
class Product
has_many :orders
end
class Order
attr_accessor :deliverable # to contain temporary data on how many items can be delivered for this order
belongs_to :product
end
somehow i want to have
Order.all_deliverable
that will calculate the Product...
How to initialize variables in ActiveRecord class?
Variables here is the variables that are outside the scope of database
such as:
class Product
attr_accessor :used
end
I want to initially assign @used initially to false, later if some person access the product, i will change @used to true
First i thought of putting @used=false i...
I can't seem to get this one right at the moment.
I want distinct records but I need other attributes to come along with the results of the find method. Current nonworking code is:
Visit.find(:all, :select => "user_id, DISTINCT cookie")
...
Hey All,
I have decided to use SubSonic (v3.0) for the first time and thoroughly enjoy it so far however I seem to have stumbled and I am hoping there is a nice neat solution.
I have a users, roles and joining table.
SubSonic (ActiveRecord) generated an entity User for my users table. A property of User is UserRoles and is of the type...
I have a simple standalone model that doesn't inherit from ActiveRecord or anything else, called SmsSender. As the name suggests, it delivers text messages to an SMS gateway.
I also have an ActiveRecord model called SmsMessage which has an instance method called deliver:
def deliver
SmsSender.deliver_message(self)
self.update_attri...
Hi all,
I'm using will_paginate to paginate my geokit search results. The code works, however, when looking at the log it does double the geokit query when using the following will_paginate call:
@posts = Post.paginate :page => params[:page], :per_page => 1,
:origin => @search, :within => @miles, :include => :u...
The illustration is like this:
class Product
end
class SalesOrder
belongs_to :product
belongs_to :customer
att_accessor :deliverable
# give all sales orders that are deliverable because the stock is ready
# and also assign deliverable
def self.calculate_deliverable
all_so = SalesOrder.find(:all, :order => 'input_date ...
When I print an ActiveRecord of a Department, I get:
Department:0x210ec4c {
:id => 3,
:name => "Computer Science",
...
:school_id => 3
}
How can I make it give me the School instead of the School_ID? In other words, call to_s on the school found by the school_id. Just lik...
Models:
* Person
* Club
Relationships
* Membership
* Committee
People should be able to join a club (Membership)
People should be able to be on the board of a club (Committee)
For my application these involve vastly different features, so I would prefer not to use a flag to set (is_board_member) or similar.
I find myself wanting ...
I have two models questions and answers. and a question has_many answers.
How can I find out all the questions which don't have any answer?
...
This rails project is very bare-bones, just begun, so I haven't done any weird loopholes or patching.
The model, to_s replaces school with bar if nil:
class Department < ActiveRecord::Base
belongs_to :school
def to_s
"foo" + (school || "bar")
end
end
Says the view:
can't convert ActiveRecord::Associations::BelongsToAssocia...
I would like to setup ActiveRecord iSession with Ninject IoC just like SubSonicSimple is done.
http://mvcstarter.codeplex.com/
Pls help ;)
...
In Django, you fully describe your models in models.py. In Rails with ActiveRecord, you describe part of a model in in the /models directory, and part of it in migrations. Then ActiveRecord introspects model properties from the existing database tables.
But I find migrations, columns, and tables to be a headache.
How can I do like ...
I know that if I name a column in a table "othertablename_id" rails will know to use that column for a belongs_to or other relation. If I want to have multiple id's from the same table, obviously this won't work, because I would have duplicate column names. What is the best way to build a table that relates two rows from the same table? ...
hi,
I have a table without an ID column. When I try to delete from it using ActiveRecord the generated SQL is DELETE FROM table_name WHERE ID=NULL, which obviously doesn't work. Is there any way to delete from the table using ActiveRecord, or at least run a raw SQL delete query with placeholders (so it's not vulnerable to SQL injection)...
For example:
class Product
has_many :sales_orders
def total_items_deliverable
self.sales_orders.each { |so| #sum the total }
#give back the value
end
end
class SalesOrder
def self.deliverable
# return array of sales_orders that are deliverable to customer
end
end
SalesOrder.deliverable #give all sales_orders t...