activerecord

Can't get Rails :autosave option to work on models

This may be something totally simple, but I can't for the life of me get this working. For some reason, :autosave isn't actually autosaving underlying models. Here is my schema: create_table :albums do |t| t.string :title t.text :review t.timestamps end create_table :songs do |t| t.integer :album_id t.string :name ...

code igniter update a row using active records

hi All programmer I wanted to update a row using active records in codeigniter, and I only want to increment a field value (received_qty = received_qty +1) , I realized that I can do that in usual sql, but I cant in codeigniter active records $update['received_qty'] = 'received_qty + 1'; $update['received_date'] = date("Y-m-d"); $this-...

What Are The Advantages and Disadvantages of Putting ActiveRecord Methods into Modules?

What are the advantages and disadvantages of creating a module like: module Section def self.included(base) base.class_eval do has_many :books end end def ensure_books return false if books <= 0 end end ...where ActiveRecord methods are used in the module instead of directly on the class(es) they belong to? ...

ActiveRecord::EagerLoadPolymorphicError: Can not eagerly load the polymorphic association

class Transaction < ActiveRecord::Base belongs_to :account, :polymorphic => true end class Bankaccount < ActiveRecord::Base has_many :transactions, :as => :account end class Creditcard < ActiveRecord::Base has_many :transactions, :as => :account end Trying to do a summation of transactions where the account is active. Transacti...

Is there any way to non-verbosely output all dependencies using to_json?

In Rails apps, I find myself placing a lot of nested :include => statements in my JSON rendering code to include objects with relationships(direct and indirect) to the root object. Is there any way to get to_json(or a similar method) to automatically include all related objects without explicitly specifying them? ...

ruby/rails NoMethodError? when using custom validation method

hi all, i'v been new to ruby and rails and encountered a rather strange error: class Person < ActiveRecord::Base validates_presence_of :description, :if => require_description_presence? def require_description_presence? self.can_send_email end end raises NoMethodError in PeopleController#index undefined method ...

ActiveRecord serialize using JSON instead of YAML

I have a model that uses a serialized column: class Form < ActiveRecord::Base serialize :options, Hash end Is there a way to make this serialization use JSON instead of YAML? ...

Problem In Updating the existing record in subsonic 3.0

private Boolean Saveuser(bool isNew) { tb_User user = new tb_User(); user.User_Name = txtUserName.Text.Trim(); user.User_LoginName = txtLoginName.Text; user.User_Password = txtPassord.Text; user.User_ModifiedBy = clsGlobalVariable.strusername; user.User_Modified = DateTime.Now; user.User_IsDeleted = false; ...

Get Activerecord list of associated objects from list of objects

Hello, I'm fairly new to Rails, and so I apologise if this is a daft question. I've tried looking around the web for the answer, but I'm not totally sure on the terminology and so I'm finding it really difficult to get an answer. Basically, I have two models 'Group' and 'Category'. Groups has_one Categories, and Categories belongs_to ...

Active Record find conditions as string

hi i have some conditions to pass to a finder. The problem is that i don't want to pass in an usafety way. So imagine that i receive a hash: hash = {:start_date=>'2009-11-01',:end_date=>'2010-01-23'} i would like to pass it to my finder like: Model.find(:all,:conditions=>"created > '#{start_date}' and created < '#{end_date}'") The...

Changing from raw sql to codeigniters active class

I have this SELECT * FROM categoryTable WHERE categoryId NOT IN ( SELECT categoryId FROM userMenuTable WHERE cookieId = 'bang4b544417a41b6' ) but I would like it use codeigniters active record class so using $this->db syntax, I was hoping someone would help me convert this? ...

Companies to do code review of crypto in an ActiveRecord / Ruby on Rails webapp?

We have written a Ruby on Rails application that allows a visitor to fill out a form with personal information (name, address & other confidential details), which is stored in a database until the information can be collected by a batch process running inside institution's firewall. To prevent attackers from getting this confidential in...

How to find only the users who have posted at least one comment

I am using Rails 2.3.5 . This is a standard case. Tables are: users, comments, user_comments . I need to find all the users who have status 'active' and have posted at least one comment. I know comments table can have foreign key but this is a contrived example. There are two users in the table. There are two comments. Both the commen...

:autosave property of has_many associations broken in Rails 2.3.4?

Before I post this as a bug to the rails team, I wanted to see if I'm doing something wrong that may be causing this behavior. Specifically, the :autosave property of has_many associations doesn't seem to be working as per the docs. For reference, here is the most current API documentation: http://api.rubyonrails.org/classes/Acti … ati...

Rails: has_many with extra details?

While I'm not a complete Ruby/Rails newb, I'm still pretty green and I'm trying to figure out how to structure some model relationships. The simplest example I can think of is the idea of "recipes" for cooking. A recipe consists of one or more ingredients and the associated quantity of each ingredient. Assume we have a master list in th...

How can I order by attributes of multiple subclasses that inherit from the same base class in Ruby on Rails?

I have 4 classes - Patient, Doctor, Person, and Appointment. Patient and Doctor are subclasses of Person. Appointment belongs to Patient and belongs to Doctor. I want to write an AR statement to sort appointments by the patient's last name and another to sort by the doctor's last name, as all appointments will be in a sortable table. ...

One model - many DB connections in Rails?

(using Ruby on Rails and ActiveRecord) In short: Is there some way how a model can use different DB schema for each request? Why I need id: I have a working intranet application working for one company but I decided I would like to offer it to other companies. The Rails way would be to add company_id to each model and alway use this sc...

"merging" multiple models. To create a "recent activity" box

How do you merge models so that I can have the last 10 Posts, Feed Entries and Private Messages displayed in order? Posts are stored in the "Post" model and ordered on "created_at" Feed Entries are stored in "Planet" and ordered on "published_at" Private Messages are stored in "Message" and need to be filtered with: :conditions => "r...

Failing to connect to oracle database

I'm trying to write a jruby script that connects to an oracle database using jdbc. Thusfar I've got: require 'rubygems' require 'jdbc_adapter' require 'active_record' require 'active_record/version' ActiveRecord::Base.establish_connection( :adapter => 'jdbc', :driver => 'oracle.jdbc.driver.OracleDriver', :url => 'jdbc:oracle...

Rails Nested Attributes Association Validation Failing

I have nested attributes for a Rails model and the associations validations are failing for some reason. I am not useing accepts_nested_attributes_for, but I am doing something very similar. class Project < ActiveRecord::Base has_many :project_attributes def name project_attributes.find_by_name("name") end def name=(val) ...