activerecord

Rails 4: Using PostgreSQL function in order causes error in query due to the includes table not being joined

孤街醉人 提交于 2019-12-08 10:40:25
问题 I found an odd problem with Rails 4 Active Record queries where the includes table is not joined if I use a PostgreSQL function in the order. This same query works fine if I remove the PostgreSQL function. This works fine... Widget.includes(:sprocket).order("sprockets.name").all This fails because the includes relationship is not joined... Widget.includes(:sprocket).order("lower(sprockets.name)").all Notice the only thing different is the lower(sprockets.name). I know I can add .references

RIA DomainService + ActiveRecord

假如想象 提交于 2019-12-08 10:20:27
问题 I tried to use SubSunsonic.ActiveRecord in SL3 project that uses .NET RIA Services. However when I try to return some IQuerable in DomainService class I get an error that the classes generated by Subsonic have a property 'Columns' with an unsupported type. That's what I have public IEnumerable<SE_NorthWind.SuperEmployee> GetIntegers() { return SE_NorthWind.SuperEmployee.All() .Where(emp => emp.Issues > 100) .OrderBy(emp => emp.EmployeeID); } And this is the error I get Error 7 Entity 'SE

Rails form_for NoMethodError

谁说胖子不能爱 提交于 2019-12-08 09:54:10
问题 I am trying to generate a form using erb in a rails application. I am continually getting the NoMethodError for line #3 of my .html.erb file. Below is the migration, the controller, the model, and the .html.erb The error is "undefined method `class_projects_path'" Migration: class CreateClassProjects < ActiveRecord::Migration def change create_table :class_projects do |t| t.string :name t.text :description t.text :summary t.text :github t.text :other_url t.timestamps end end end Model: class

How can I do “rake db:migrate” with mongoid and active record?

不羁岁月 提交于 2019-12-08 09:50:20
问题 I want to migrate active record (mysql) database. I use database both mongoid and active record. I typed this code. rails generate active_record:migration CreateUsersTable It worked. But I can't migrate it with active_record. How can I migrate active record like rake active_record:db:migrate ? 回答1: I found my problem. I missed adding active_record/railtie to application.rb After I added following line, it works! require "active_record/railtie" 回答2: I experimented with mixing both AR and

findind all using .all vs. where

六眼飞鱼酱① 提交于 2019-12-08 09:33:36
问题 In my controller i am getting all entries form a table like this @enums = Enuemerations.all Then later i want to search and get the name from by doing @enums.find(107).name I get an error undefined method `name' for #<Enumerator:0xb5eb9d98> So I tried it out in the rails console and found this working Enumeration.where(false).find(107) where this does not work Enumeration.all.find(107) Can someone explain to me how this works? Thanks 回答1: Using Enumeration.all instantly queries the database

Rails group a table by :created_at, returning a count of the :status column, and then sub-group the :status column with count of each unique value

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 08:52:31
问题 I have a model Notification and I would like to know how many notifications are created per days and how many with each status. status is a string key of the model Notification. Notification.where(user: users).group('DATE(created_at)').count('created_at') That give me : {Mon, 05 Oct 2015=>2572, Tue, 06 Oct 2015=>555, Wed, 07 Oct 2015=>2124, Thu, 08 Oct 2015=>220, Fri, 09 Oct 2015=>36} But I would like something like : {Mon, 05 Oct 2015=>{total=>2572, error=>500, pending=>12}, Tue, 06 Oct 2015

Rails iterate over only the persisted records associated to an object

蹲街弑〆低调 提交于 2019-12-08 08:45:20
问题 I have something like this in my show action: def show @blog = Blog.find(params[:id]) @new_comment = @blog.comments.build end Now in the view I do two things: I render the _form.html.erb for the Comment so that the user can add a comment to this blog I want to be able to iterate over the existing comments for this blog in order to display them. I am having problems with number 2 . The issue is that as I iterate over the associated comments with this: <% @blog.comments.each do |comment| %> It

Ruby, windows, active_record, and Control-C

孤人 提交于 2019-12-08 08:17:24
问题 What is active_record doing to the signal processes under windows (I don't see this with the same versions on the mac) that causes it to behave so strangely? For instance: require 'rubygems' trap("INT"){puts "interrupted"} puts __LINE__ sleep 5 require 'active_record' trap("INT"){puts "interrupted again"} puts __LINE__ sleep 5 When I run the above code (ruby 1.8.6, gem 1.3.1, activerecord 2.2.2,) I can hit ^C as many times as I like during the first sleep, but the first interrupt after the

Requiring ActiveRecord on IRB - Ruby (NO Rails)

浪尽此生 提交于 2019-12-08 08:17:22
问题 How can I load ActiveRecord on an IRB session? I have the following # config/app.rb require 'active_record' ActiveRecord::Base.establish_connection( adapter: 'sqlite3', database: 'db/mydb.sqlite3' ) But when I start IRB and try to load it irb#1(main):001:0> require config/application.rb I get NameError: undefined local variable or method `config' for main:Object Did you mean? conf I'd like to be able to interact with my ActiveRecord objects from IRB. I'm NOT using Rails but only ActiveRecord.

Rails3 cannot save 'ñ' to Oracle 11g

浪子不回头ぞ 提交于 2019-12-08 08:16:19
问题 I'm using Rails 3.2.13, ruby 1.9.3 and Oracle 11g. When saving a record in the DB with a character like 'ñ' I get the error below: ActiveRecord::StatementInvalid (Encoding::UndefinedConversionError: U+00F1 from UTF-8 to US-ASCII: INSERT INTO "OMNIAUTH_USERS" ("CREATED_AT", "FIRST_NAME", "ID", "LAST_NAME", "STATUS", "UID", "UPDATED_AT") VALUES (:a1, :a2, :a3, :a4, :a5, :a6, :a7)): app/controllers/user_sessions_controller.rb:18:in `create' I tried to run this query to see the language used by