I have an activerecord model and set of validators to it, But I also have to provide front end validation.
Is there a gem or a smart way to use activerecord validators, for instance in jquery validation plugin, instead of writing it by hand?
Thanks
...
I'm new to ActiveRecord. I realized that I had forgotten to add a default value for a column in one of my tables. I want to create a migration to fix this, but I can't figure out how. Is there an alter_column method that you can call during migrations? If not, how can I do it?
EDIT: I just tried using change_column, but this causes an e...
I have this schema:
class Comment
has_many :ratings, :as => :target
end
class Rating
belongs_to :target, :polymorphic => true
end
I want to write a named scope that will sort comments by their average rating, without fetching the whole list of comments and then fetching all their ratings.
I think I need to use :include and :grou...
Is there a way to see all generated queries from rails in production environment like you can in development?
...
What is the correct way to model many has_one (or even has_many) relationships on a model where each has_one is just a different role/context of some class?
class Group < ActiveRecord::Base
has_many :memberships, :as => :membered
has_one :admin, :class_name => "User", :through => :memberships
has_one :speaker, :class_name => "User...
I have an object called human and that object has a field called job. I want users to be able to add their own jobs (which will obviously be added in their own language) but I want to have any job that is a default in the database to be translated when someone does a Human.job, can rails translate the default if it is in the view but not...
Hi all,
I have 2 polymorphic associations through which I need to query.
I have a news_article table which has a polymorphic association to teams, players, etc. Those teams, players, etc have a polymorphic association to photos through phototenic.
I need to find all articles that have at least one picture that is 500px wide.
The Ar...
I think the problem is trivial.I have two models: User and Betting.
User
has_many :bettings
Betting
belongs_to :user
I just want to get the users ordered by who made more bettings.
Sorry, for my english
Thanks in advance
Francesco
...
Hi,
I have articles and categories in a n:m relation:
I looking for a find statement on the Category Model so that I can get all categories witch consist at least one article.
Should be easy, but I didn't find a efficient solution, without searching retrieving all the articles.
Thanks,
Maechi
...
Greets to ruby developers.
I'm stuck with ActiveRecord model associations.
I illustrate what I want to do by a tables. I have these tables:
Products:
+----+-----------+
| id | name |
+----+-----------+
| 1 | Cellphone |
+----+-----------+
Images:
+----+-------+--------------+----------------+
| id | url | imageable_id | image...
I'm using the rails3-jquery-autocomplete gem found here: http://github.com/crowdint/rails3-jquery-autocomplete
The instructions are clear for how to query a single attribute of a model and I am able to make that work without a problem.
My Person model has two attributes that I would like to combine and query, however. They are first_n...
Hello,
Im using ruby on rails with a mysql db in the back. I realized, that the characters are limited up to about 277 per column entry...
How can I increase this?
Thanks,
Markus
...
Forgive me if I've got my terminology wrong; I am still quite new to Ruby and Rails.
For school I am working on an RoR project as part of a team. I was pair programming with a teammate, who actually happens to be experienced in RoR; and I wrote something like the following:
d = self.deliverables.find_all_by_lifecycle_id(self.lifecycle_...
Hi everybody, I have a little problem: I can't compose sql-query inside AR.
So, I have Project and Task models, Project has_many Tasks. Task has aasm-field (i.e. "status"; but it doesn't matter, i can be simple int or string field).
So, I want on my projects index page list all (last) projects and for every project I want count it's ac...
Hello,
I'm using better nested set. I now want a active record statement, where I can get all top elements and include all elements of this root! How is this possible?
I think there must be a possibility to include all the childrens into their root elements in one statement...
Does anybody have an idea how to do this?
Thanks for your...
I have an Author model which habtm :feeds. Using Rails 3 want to setup a scope that finds all authors that have no associated feeds.
class Author < ActiveRecord::Base
has_and_belongs_to_many :feeds
scope :without_feed, joins(:feeds).where("authors_feeds.feed_id is null")
end
...doesn't seem to work. It feels like a simple t...
Hello,
I have installed multiple state_machine gems to my app to use them for a notification system but every time I run into an ActiveSupport issue. It usually looks something almost identical to this:
>> m = Message.new
TypeError: wrong argument type nil (expected Module)
from /home/Ryan/appname/app/models/message.rb:2:in `i...
Ive got projects and devices which are linked to each other in a many-to-many relation. On creation of a project the user gets a list of available devices to link to the project using checkboxes. The controller code for create is shown below.
I am using ASP MVC with ActiveRecord.
public ActionResult Create()
{
ViewData["devices...
Basically what I want to do is to log an action on MyModel in the table of MyModelLog. Here's some pseudo code:
class MyModel < ActiveRecord::Base
validate :something
def something
# test
errors.add(:data, "bug!!")
end
end
I also have a model looking like this:
class MyModelLog < ActiveRecord::Base
def self.log_so...
I've got a class structure similar to this for a family of classes using STI
class Root < ActiveRecord::Base
attr_accessible :root_prop
end
class Child < Root
attr_accessible :child_prop
end
class Grandchild < Child
attr_accessible :gc_prop
end
All my properties were working fine until I added the attr_accesible markers, so I...