This is driving me insane! This code used to work fine, but as of a few weeks ago it stopped working, and I can't work out why. Basically a Game has many Patches. The error occurs in my PatchesController, but its reproducible in the rails console like this:
first_game = Game.find(:first)
first_game.patches
As soon as I use the patches...
Right now I have this social media app, where I'm implementing ratings on users per category, What i want to do it's:
Whenever an user casts a vote on an article, it will grab all the votes on the article and make an average of the score/votes and insert that value into another model that i have (User Category Rating), now my question i...
Hi everyone!
I have an applications that stores players ratings for each tournament. So I have many-to-many association:
Tournament
has_many :participations, :order => 'rating desc'
has_many :players, :through => :participations
Participation
belongs_to :tournament
belongs_to :player
Player
has_many :participations
has_ma...
I'm getting a submitted form in this way:
$resume->attributes = $_POST['ResumeModel'];
$profile->attributes = $_POST['UserProfile'];
Both CActiveRecord models are correctly populated before this from the corresponding tables, they have the correct data and all.
Both models' data is present on $_POST as modified by the form.
But it see...
I have models like this:
class Discussion < ActiveRecord::Base
has_many :comments
has_one :special_comment, :class_name => "Comment"
end
class Comment < ActiveRecord::Base
belongs_to :discussion
# contains author
end
How can I select every Discussion through its adjoined :special_comment 'author' association. Effectively I w...
My data resembles this:
class Team < ActiveRecord::Base
has_many :persons
has_one :leader
end
class Person < ActiveRecord::Base
belongs_to :team
end
Person only belongs to one Team, but of the many team members there is only 1 leader.
First question: should I use belongs_to instead of has_one in the Team model?
Second: Team i...
I've been updating my user test server and now suddenly I got an error every time I invoke rake with anything database-related.
Sample error:
rake db:drop RAILS_ENV='production' --trace
rake aborted!
undefined method `[]' for false:FalseClass
/usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/tasks/databases.rake:96
Here's line 96 of...
I have a date field in a model backed form in my Rails App:
<%= f.date_select :birthday,
{:start_year => Time.now.year,
:end_year => 1900,
:use_short_month => true,
:order => [:month, :day, :year],
:prompt => {:month => 'Month', :day => 'Day', :year => 'Year'}},
{:class => 'year',
:id => 'user_birthday'}
%>
It is being v...
What causes ActiveRecord to escape newlines in a text column? Is there a way to disable this behavior? (Illustrated below):
>> TestModel
=> TestModelid: integer, value: text, created_at: datetime, updated_at: datetime
# Create model instance with newline in text column "value"
>> t = TestModel.create!(:value => "\n")...
Hello,
Our team is currently working on a WPF Desktop application with ActiveRecord and SQLCE 3.5 for backend. We've been experiencing some strange performance issues when executing queries or creating/updating records. In some cases opening a form which has a few grids and data elements that need to be populated, can take around 2 seco...
I need send an email alert when the price of a product changes.
Is it possible do this with ActiveRecord::Observer or do I need use programming logic in the edit form?
...
Rails 3...
I have a controller..
class OrdersController < ApplicationController
def index
@os_orders = OrlandoOrder.all
@ct_orders = ChicagoOrder.all
end
end
And then I have the two models defined...
class ChicagoOrder < Order
Order::ActiveRecord::Base.table_name_prefix = 'ct_schema.'
end
class OrlandoOrder < Order
...
Hello there, I'm trying to override the way rails apply and id to an associated object, for example:
There are 2 simple models:
class Album < ActiveRecord::Base
has_many :photos
end
class Photo < ActiveRecord::Base
belongs_to :album
end
And then I want to do this:
album = Album.new :title => 'First Album'
album.photos.build
alb...
I want to create user-specific validations.
User has a column called "rule_values" which is a serialized hash of certain quantities.
In a separate model, Foo, I have a validation:
class Foo < ActiveRecord::Base
belongs_to :user
n = self.user.rule_values[:max_awesome_rating] #this line is giving me trouble!
validates_presence_o...
Hello all
I want to implement a SQL statement using codeigniter active record.
UPDATE tags SET usage = usage+1 WHERE tag="java";
How can I implement this using Codeigniter active records?
Regards
...
I have two models that are not related (in the db sense) but have some common columns (Name, Email, etc.).
Class Account < ActiveRecord::Base
end
Class LegacyAccount < ActiveRecord::Base
end
For various reasons, I cannot merge these into a single model or do STI. But I would like a simple view that displays all records from both m...
I have just inherited a medium sized Rails application and I want to try to optimize it right away. I want to start with the database to ensure that indexes are placed where they need to be an so forth. I therefore need to quickly find out all possible SQL statements that ActiveRecord might make so that I can compare that with the databa...
I want ActiveRecord to lookup by a non-id column from a table.
Hope this is clear when I give you my code sample.
class CoachClass < ActiveRecord::Base
belongs_to :coach
end
class Coach < ActiveRecord::Base
has_many :coach_classes, :foreign_key => 'user_name'
end
When I do a
coach_obj.coach_classes, this rightly triggers
SELE...
Hello all,
I need to update a single field across a large set of records. Normally, I would just run a quick SQL update statement from the console and be done with it, but this is a utility that end users need to be able to run in this app.
So, here's my code:
users = User.find(:all, :select => 'id, flag')
users.each do |u|
u.flag =...
I am using an existing database with a rails app.
I can't change the table or column names.
Lets say table one is "invoices" and table 2 is "orders"
they both have a primary key that is called the same thing, lets say "order_id"
invoices can find its order by looking at the primary key "order_id" in the orders table.
Vice versa fo...