activerecord

Query does not hit the index - are these the proper columns to index?

瘦欲@ 提交于 2019-12-11 06:04:30
问题 The following query to a Postgres database is quite slow at times (4,000+ms): EXPLAIN ANALYZE SELECT "sms".* FROM "sms" WHERE "sms"."From" = 'NUMBER1' AND "sms"."To" = 'NUMBER2' AND "sms"."SmsMessageSid" = 'UNIQUE_ID' ORDER BY "sms"."id" ASC LIMIT 1; When I run psql and analyze the query, this is the result: Limit (cost=5045.12..5045.12 rows=1 width=609) (actual time=57.011..57.011 rows=0 loops=1) -> Sort (cost=5045.12..5045.12 rows=1 width=609) (actual time=57.009..57.009 rows=0 loops=1)

Rails erb alterantive to fields_for find specific record

流过昼夜 提交于 2019-12-11 05:41:08
问题 I'm new to rails, and trying to modify an existing application. I have a model that has a 'has_many' relationship with another type of record 'group_parameters'. Group parameters has two fields (name and value). I currently have a form that scopes group_parameters and prints all the stored records. This is achieved by doing <%= f.fields_for group_parameters do | builder | %> Attribute <%= builder.text_field(:name) %> <% end %> Instead I'd like to only display certain records where the name

Yii CGridview - search/sort works, but values aren't being displayed on respective cells

淺唱寂寞╮ 提交于 2019-12-11 05:40:14
问题 I am semi-frustrated with this Yii CGridView problem and any help or guidance would be highly appreciated. I have two related tables shops (shop_id primary) and contacts (shop_id foreign) such that a single shop may have multiple contacts. I'm using CGridview for pulling records and sorting and my relation function in shops model is something like: 'shopscontact' => array(self::HAS_MANY, 'Shopsmodel', 'shop_id'); On the shop grid, I need to display the shop row with any one of the available

Rails not parsing database URL on production

社会主义新天地 提交于 2019-12-11 05:32:35
问题 I have the following database.yml file: default: &default adapter: postgresql encoding: unicode pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 4 } %> development: <<: *default database: backoffice_authentication_development test: <<: *default database: backoffice_authentication_test production: <<: *default url: <%= ENV['DATABASE_URL'] %> and I have a DATABASE_URL on production similar to postgresql://user:passwrd@backoffice.xxxxxxxx.xxxxx.rds.amazonaws.com/backoffice_api when I try start my app

How to limit character/word count on database string value in Sinatra/Active Record?

我是研究僧i 提交于 2019-12-11 05:13:55
问题 I have a column in my ActiveRecord database that I want to have a certain word limit. Essentially, I've created a form that allows users to enter text(string). I want to limit the amount of characters that are allowed in that string. @allposts = Post.limit(20) This is what I have so far in the get method for the /current page that posts all of content. 20 = number of posts shown. I also have a /new page where users will post new content. 回答1: You can limit the number of characters in a few

Rewrite JSON structure and include an EACH loop in Rails

假如想象 提交于 2019-12-11 05:12:44
问题 I have a list of shows in a database that need to be output in a certain JSON style in order to work with Polymaps. Part of this includes the need to iterate over one section in order to create a list of points. I'm pretty certain that this needs to be achieved using :include in the render :json => @results bit of the code. Here's the code as it stands: def gigs @gigs = Show.where(:displayname => "Vans Warped Tour 2011") @giggage = [{ :type => "FeatureCollection", :features => [ @gigs.each do

Nested form error in Rails app

混江龙づ霸主 提交于 2019-12-11 05:11:34
问题 Models relevant to this question: user, friend, interest, person_interest. Person_interest is polymoprhic and can store interests that either belong to a user or a friend. Interests is pre-populated with approx. 30 interests. When a user registers they are asked to select their own interests, then lower in the form enter in their friends names select the interests of that person. Trying to achieve this with <%= friend_f.input :interests, :as => :check_boxes, :label => false %> but getting the

Rails: method chaining in model

天大地大妈咪最大 提交于 2019-12-11 05:08:33
问题 Trying to create a search method in my model and join conditions based on arguments passed to the method. However, nothing gets chained after the initial "where" Controller: Item.search(args) Model: def self.search(args = {}) include ActsAsTaggableOn # Tagging model for search result = where("title LIKE ? OR description LIKE ? OR tags.name LIKE ?", "%#{args[:search]}%", "%#{args[:search]}%", "%#{args[:search]}%") .joins("JOIN taggings ON taggings.taggable_id = items.id") .joins("JOIN tags ON

Rails 5.2.2 (active record) WITH statement

假装没事ソ 提交于 2019-12-11 05:06:31
问题 I am using Rails 5.2.2 and have a complex query using a 'WITH' statement that I need to create with a left outer join. How do I do a WITH statement in active record? My TOTAL_PROFILES, is driven with a Query object and will change, while the rest will always be constant. So a basically want to wrap my query object results with the WITH statement. Here is a simplified SQL example and hoping someone can guide me to the best way to accomplish this in rails, as I see no way to do it. I have a

Rails 3.x How to write update all based on row value?

北城以北 提交于 2019-12-11 04:59:54
问题 I would like the following SQL query to be executed in a migration file after adding a column (updating the new field with existing column value from the same row) UPDATE users SET last_login=updated_at; The SQL statements work properly when executed on the database, but in rails I tried multiple syntax using the ActiveRecord update_all method but without success User.update_all("last_login=updated_at") I get the following error ActiveRecord::StatementInvalid: PGError: ERROR: current