activerecord

Accessing a database on a VPN

六月ゝ 毕业季﹏ 提交于 2019-12-24 09:26:15
问题 My Rails 3.2 app connects to a number of external servers, one of which is an SQL Server database (I connect to it using ActiveRecord + tinytds). Today, the database host decided to make it necessary to be on their VPN to access the database. My connections are now failing. How can I connect my Rails app (or just the connection to this database) to a VPN, so that I can access this database? My app is hosted on Heroku. 回答1: Short answer: you can't. You're going to have to switch hosts. Longer

Can I have a one way HABTM relationship?

为君一笑 提交于 2019-12-24 09:25:00
问题 Say I have the model Item which has one Foo and many Bars. Foo and Bar can be used as parameters when searching for Items and so Items can be searched like so: www.example.com/search?foo=foovalue&bar[]=barvalue1&bar[]=barvalue2 I need to generate a Query object that is able to save these search parameters. I need the following relationships: Query needs to access one Foo and many Bars. One Foo can be accessed by many different Queries. One Bar can be accessed by many different Queries.

Order a query by the sum of two “has_many” sub-tables?

岁酱吖の 提交于 2019-12-24 07:59:30
问题 In my app, Invoice has_many item_numbers and Invoice has_many payments . Each invoice has a balance, which is the sum of the ItemNumber amount attributes, less the sum of the Payment amount attributes. The balance is very easy to calculate in the invoice model, but I am trying to write a query that sorts invoices by balance and this is proving much harder to do in ActiveRecord/SQL. I have successfully managed to order the invoices on the total of the item_numbers with the following query

undefined method on ActiveRecord::Relation object

自古美人都是妖i 提交于 2019-12-24 07:25:47
问题 the following code fieldvalue = Admin::FieldValue.where(:item_id => @admin_item.id, :field_id => key) fieldvalue.update_attributes(:value => value) raise the following error NoMethodError (undefined method `update_attributes' for #<ActiveRecord::Relation:0x00000102dfc868>): why is it a Relation object and not a FieldValue object, what's the right way to manage this 回答1: fieldvalue should return only one value? fieldvalue = Admin::FieldValue.where(:item_id => @admin_item.id, :field_id => key)

Rails 5: group records by “DateTime” field in tree view

為{幸葍}努か 提交于 2019-12-24 07:15:14
问题 I'm struggling to implement tree view. I have a table where there is DateTime field. I need is to create a view something like this where records are group by that single DateTime field values : -Year -Month -Day /All records belonging to particular day is populated.../ ... There can be multiple years, months, days so records have to be grouped accordingly. For record grouping purposes I could use Groupdate gem. Any hint on how to build something like this in controller/model would be great.

failed to allocate memory on the console and internal server error on the browser

不问归期 提交于 2019-12-24 07:09:42
问题 I have this error while loading the data from files in to database. Please help me out in getting this right. here is the method : clusters.each do |cluster| cluster_path = cluster.path root = current_root + cluster.name+'/' Log.info "<br/> --------- Starting data popuation for #{cluster_path} ---------------" population_time[:bp_data] = populate_bp_data(root+fileName[:bp_data], cluster_path, @dataset.id) population_time[:m_lint] = populate_m_lint(root+fileName[:m_lint], cluster_path,

Rails in what order do model callbacks happen for nested parent/ child models?

↘锁芯ラ 提交于 2019-12-24 06:59:12
问题 I know that the general order in which models are saved is the deepest child first, and then gradually up to the parent. But I'm wondering with respect to other callbacks, does it happen something along the lines of: ChildA - before validation ChildB - before validation Parent - before validation ChildA - after validation ChildB - after validation Parent - after validation ChildA - before save ChildB - before save Parent - before save ... OR along the lines of: ChildA - before validation

Pulling multiple levels of data efficiently in Rails

眉间皱痕 提交于 2019-12-24 06:58:41
问题 I am trying to build a print process, which consists of printing a batch of financial applications using Rails. I am printing around 100 applications, which consist of multiple levels of data (the application itself, sub-models, and their sub-models). At the moment the page is very inefficient as it is doing a lot of N+1 querying which is causing the performance to be poor. Question is, is there an efficient way of getting this data out of the database. I've tried pulling the forms with

Why is this ActiveRecord statement failing in Server but not Console

天涯浪子 提交于 2019-12-24 06:36:20
问题 I have the following query which is failing in rails s in a particular controller. It's not failing in rails c . Post.includes(:user).find(:all, :limit => 10, :order => 'users.display_name ASC') In the console it returns the correct data. In the server, I get this error ActiveRecord::StatementInvalid: PGError: ERROR: column posts.users.display_name does not exist LINE 1: ...s_count" AS t0_r7, "posts"."popularity" AS t0_r8, "posts"."u... ^ The query is long and I'll just include a few relevant

Using Closure_tree gem instead of Awesome nested set

给你一囗甜甜゛ 提交于 2019-12-24 06:35:30
问题 Hi I followed the link to set up closure_tag gem. When i tried to use closure_tree syntax in the following way (newStructure.find_or_create_by_path(parent) instead of newStructure.move_to_child_of(parent)) ... got the following error : "Can't mass-assign protected attributes: ancestor, descendant, generations" is this the correct way of using newStructure.find_or_create_by_path(parent) ? def self.import(path) newStructure = FileOrFolder.find(:first, :conditions=>["fullpath = ?", path]) if