Hello, I am currently experiencing a strange issue with our users being logged out. I haven't been able to reproduce it explicitly.
The Rails application is using the default CookieStore.
My initial hypothesis is that somehow the session data within the cookie, or even the cookie itself is being destroyed. This may be either from a use...
Hi all,
I have a models User
class User < ActiveRecord::Base
has_many :ratings
has_many :rated_films, :through => :ratings, :source => :film
end
and Films
class Film < ActiveRecord::Base
has_many :users, :through => :ratings
end
I am looking to find all Films that have not been rated by the specified user...
Hello,
I'm having difficulties with translating following SQL syntax into Criteria API:
SELECT AVG(dbo.Member.Points) FROM dbo.Member WHERE dbo.Member.PaidMemberRegDate IS NOT NULL;
I have a Member class with a Points property. I just want to get the average Points of all Members that have the property PaidMemberRegDate set to null.
...
Here is the setup:
end_date = DateTime.parse('2010-01-01 12:00:00-04')
and sometimes it's initialized:
end_date = 1.days.ago
The question... do these named_scope(s) generate the same EXACT SQL?
named_scope :before, lambda { |end_date|
{ :conditions =>
["overdraft_transaction_payments.created_at < ?", end_date] }...
Hi guys I know that this is really bad idea but I want join three tables for my query on polymorphic association
for example
class Article
has_many :comments, :as=>:commentable
end
class Post
has_many :comments, :as=>:commentable
end
class Comment
belongs_to :commentable, :polymorphic=>:true
end
and I need to get something s...
How do I eager-load only some of the objects in a has_many relationship?
Basically, I have four objects: Assignment, Problem, AssignmentUser, and ProblemUser.
#assignment.rb
has_many :problems
has_many :assignment_users
#assignment_user.rb
belongs_to :assignment
belongs_to :user
has_many :problem_users
#problem.rb
belongs_to :assig...
Step 1: [setup]
a = Aritcle.new(:some_boolean => false)
a.save
write_to_memcache(a.id, Marshal.dump(a))
b = Marshal.load(read_from_memcache(a.id))
If I do:
b.some_boolean = nil
b.save
the some_boolean is not written back to the DB. DB still remains false.
But:
a.some_boolean = nil
a.save
works perfectly. DB is set to NULL.
A...
Say I have the following in my console:
@user.favcolors
=> [#<FavColors id: 1, color_id: 18, fav_id: 1>,
#<FavColors id: 2, color_id: 19, fav_id: 1>]
@user.favcolors.count
=> 2
However, since fav_id is same in both results (1). I want this count to be 1, instead of 2.
Is there a way I can put where clause in the code @user.fav...
Hi guys,
I'm developing a system with codeigniter, in my situation i have to press a link in one user interface and get it's ID and pass it to the model and get the data relevant to that ID and go to the other interface and display the data in the relevant fields, i know how to pass data from model to view, but i don't know how to pass ...
I have several similar Models (ContactEmail, ContactLetter, ContactPostalcard).
Each instance (record) in, say, ContactEmail, means a specific Email template was sent to a specific Contact.
So, each one (e.g. ContactEmail) belongs_to :contact
So, in ContactEmail model, there is an attribute ContactEmail.contact_id.
Each Contact has a...
They seems to be similar.
...
Hey.. I've run into a problem using several "like" in my sql-query (generated with Codeigniter's activerecord):
SELECT * FROM (`posts`) WHERE `city` LIKE '%test%' AND `title` LIKE '%%' OR `text` LIKE '%%'
Thing is, it appears to read this query as if there was a parenthesis around the first like and the second like, but I want there t...
Hello, coming from my experience with nHibernate, I wonder how one maps (n)hibernate's component classes in ActiveRecord
class Person < ActiveRecord::Base
#somehow get a :name attribute here
end
class Name
@fist_name
@last_name
end
how can this be done with one table only (so this is no 1:1, but i want to have a :name_first_na...
I planned on using this module (full exmpample here http://pastie.org/1098444)
puts "Name_and_key was referenced."
module Name_and_key
def normalize(s)
s.mb_chars.normalize(:kd).gsub(/[^\-x00-\x7F]/n, '').to_s
end
def name=(name)
self[:name] = name
self[:key] = normalize(name).downcase
end
def name
self[:na...
I want to group my data by the hour/day possibly even to the quarter hour.
Can I do this directly in ActiveRecord or should I just grab all the data and do the aggregation manually?
Table "Checkin":
Time NumBikes ChangeBikes
09:00 5 5
09:05 6 1
09:10 10 4
10:00 6 4
10:05 8 ...
Not sure on my Ruby syntax here.
I want to define a method that I can call like this: client.invoices.average_turnaround. So my average_turnaround method needs to work with a collection of ActiveRecord objects.
Here's my code thus far:
class Invoice < ActiveRecord::Base
...
def self.average_turnaround
return self.map(&:turnaro...
Using the tutorial "Find Stuff (quick and Dirty)" in "Advance Rails Recipes", I can find stuff in the development environment but not in the production environment.
NoMethodError: undefined method `searchable_by'
I have this code in "lib/searchable.rb"
module Searchable
def searchable_by(*_column_names)
@search_columns = []
...
When working with activerecord I notice that while constructing associations, the reciprocal association is provided automatically only if the reciprocal model has already been saved. If it has not yet been saved, this reciprocal association must be defined manually. I am wondering if this is intentional or a bug, since the only differ...
I have a Ruby on Rails application in which the code directly access many-to-many join tables directly. This makes modifying some of the code very difficult since it bypasses the normal associations and methods created via the :has_many and :has_many :through relationships.
My question is simply, is this an acceptable thing to be doing ...
Simple question that used to puzzle me about Rails:
Is it possible to describe a Model's structure from within the model rb file?
From what I understand a model's data structure is kept within the migration, and the model.rb file is supposed to contain only the business logic.
Why is it so? Why does it make more sense to migrate the d...