ruby-on-rails-4.1

Where has create/create_record gone in ActiveRecord?

随声附和 提交于 2019-12-08 04:26:16
问题 I have an audit monkey patch to ActiveRecord that works on all versions of Rails from 2.x to 4.0.2 but does not work with ActiveRecord 4.1. The code for 4.0 looks like this module HLLAuditStamps def self.included(base) # create/update became create_record/update_record in Rails-4.0 base.alias_method_chain :create_record, :audit base.alias_method_chain :update_record, :audit private def create_record_with_audit set_audit_attributes . . . This works in 4.0.2 but throws this exception in 4.1.2:

Rails 4 MySQL bigInt primary key issues and errors

旧街凉风 提交于 2019-12-07 20:10:50
问题 I need to use a 14-digit bigInt as a primary key in a rails 4.1.8 application. Using older posts on SO as a guide, I came up with the following to address this... class CreateAcctTransactions < ActiveRecord::Migration def change create_table "acct_transactions", :id => false do |t| t.integer :id, :limit => 8,null: false t.integer "account_id",limit: 8,null: false t.integer "transaction_type_id", null: false t.datetime "date",null: false t.text "description",limit: 255 t.decimal "amount"

Ruby websocket client for websocket-rails gem

怎甘沉沦 提交于 2019-12-07 05:37:18
问题 I am developing a rails webpage which need to use websocket functionality to communicate with an external ruby client. In order to do this, I am using the websocket-rails gem in the rails server, definning the client_connected client_disconnected event and a specific action to received the messages from the client (new_message). On the client side I have tried to use different ruby gems like faye-websocket-ruby and websocket-client-simple but I always obtain errors when I try to send a

Where has create/create_record gone in ActiveRecord?

不打扰是莪最后的温柔 提交于 2019-12-06 14:49:28
I have an audit monkey patch to ActiveRecord that works on all versions of Rails from 2.x to 4.0.2 but does not work with ActiveRecord 4.1. The code for 4.0 looks like this module HLLAuditStamps def self.included(base) # create/update became create_record/update_record in Rails-4.0 base.alias_method_chain :create_record, :audit base.alias_method_chain :update_record, :audit private def create_record_with_audit set_audit_attributes . . . This works in 4.0.2 but throws this exception in 4.1.2: undefined method create_record' for class ActiveRecord::Base' (NameError) If I go into rails console in

Replacement for “has_many … counter_sql” in Rails 4.1

此生再无相见时 提交于 2019-12-06 13:55:46
问题 Rails 4.1 removed the counter_sql from has_many associations, so the following does no longer work: class Project < ActiveRecord::Base has_many :backers, -> { select('COMPLEX SQL QUERY') }, through: :pledges, source: :backer, counter_sql: proc { "COMPLEX COUNT SQL QUERY" } (...) end I need a counter_sql here since with the COMPLEX SQL QUERY in select , AR does not build valid SQL when I do project.backers.count . To fix this, I'd move this to a method like so: class Project < ActiveRecord:

Very Basic Rails 4.1 API Call using HTTParty

此生再无相见时 提交于 2019-12-06 02:11:57
问题 Relatively new to Rails. I am trying to call an API and it's supposed to return a unique URL to me. I have HTTParty bundled on my app. I have created a UniqueNumber controller and I have read through several HTTParty guides as far as what I want but maybe I'm just a bit lost and really have no idea what to do. Basically, all I need to do is call the API, get the URL it returns, then insert that URL into the database for a user. Can anyone point me in the right direction or share some code

Unknown key in Rails association

自闭症网瘾萝莉.ら 提交于 2019-12-05 21:03:41
问题 I have the following associations code: has_many :rates_without_dimension, :as => :rateable, :class_name => "Rate", :dependent => :destroy, :conditions => {:dimension => nil} has_many :raters_without_dimension, :through => :rates_without_dimension, :source => :rater has_one :rate_average_without_dimension, :as => :cacheable, :class_name => "RatingCache", :dependent => :destroy, :conditions => {:dimension => nil} dimensions.each do |dimension| has_many "#{dimension}_rates", :dependent =>

Are application helper methods available to all views?

眉间皱痕 提交于 2019-12-05 17:31:33
Rails 4.1 Ruby 2.0 Windows 8.1 In my helpers/application_helper.rb, I have: def agents_and_ids_generator agents = Agent.all.order(:last) if agents agents_and_ids = [['','']] agents.each do |l| name = "#{l.first} #{l.last}" agents_and_ids << [name,l.id] end return agents_and_ids end end In my views/agents/form.html.erb, I have the following: <%= f.select :agent_id, options_for_select(agents_and_ids_generator) %> In my controllers/agents_controller.rb, I have the following: include ApplicationHelper But when I go to this view, I get the following error message: undefined local variable or method

How to run rails puma server with config file using 'rails s puma'

余生长醉 提交于 2019-12-05 11:45:05
问题 I am able to run a puma server in rails using either rails s puma or just puma . According to this answer, running rails s puma makes the server aware of the rails environment. It shows server errors etc that running puma alone does not. I want to set a config file like so: config/puma.rb workers Integer(ENV['PUMA_WORKERS'] || 3) threads Integer(ENV['MIN_THREADS'] || 1), Integer(ENV['MAX_THREADS'] || 16) rackup DefaultRackup port ENV['PORT'] || 3000 environment ENV['RACK_ENV'] || 'development

Ruby websocket client for websocket-rails gem

懵懂的女人 提交于 2019-12-05 08:57:34
I am developing a rails webpage which need to use websocket functionality to communicate with an external ruby client. In order to do this, I am using the websocket-rails gem in the rails server, definning the client_connected client_disconnected event and a specific action to received the messages from the client (new_message). On the client side I have tried to use different ruby gems like faye-websocket-ruby and websocket-client-simple but I always obtain errors when I try to send a message. On the server I can't find the way to process these messages. Both gems has a send method with only