Renaming table in rails
Remember that in Rails >= 3.1 you can use the change method. class RenameOldTableToNewTable < ActiveRecord::Migration def change rename_table :old_table_name, :new_table_name end end
Remember that in Rails >= 3.1 you can use the change method. class RenameOldTableToNewTable < ActiveRecord::Migration def change rename_table :old_table_name, :new_table_name end end
You can do as it says on the issue 1077 or as reported in this blog at noobsippets Both suggest we do the following, and can be done on rails console: Sidekiq.redis(&:flushdb) Caution: This command will clear all redis records. I suggest not using it in production another approach would be redis-cli –scan –pattern users: … Read more
Check out ActiveModel::Dirty (available on all models by default). The documentation is really good, but it lets you do things such as: @user.street1_changed? # => true/false
There are several approaches : Using ActiveSupport::Concern (Preferred) Read the ActiveSupport::Concern documentation for more details. Create a file called active_record_extension.rb in the lib directory. require ‘active_support/concern’ module ActiveRecordExtension extend ActiveSupport::Concern # add your instance methods here def foo “foo” end # add your static(class) methods here class_methods do #E.g: Order.top_ten def top_ten limit(10) end end … Read more
— Update — As of January 9th, 2015. the solution is now implemented in Rails 5 ActiveRecord’s secure token implementation. — Rails 4 & 3 — Just for future reference, creating safe random token and ensuring it’s uniqueness for the model (when using Ruby 1.9 and ActiveRecord): class ModelName < ActiveRecord::Base before_create :generate_token protected def … Read more
From within rails you can create a configuration object and obtain the necessary information from it: config = Rails.configuration.database_configuration host = config[Rails.env][“host”] database = config[Rails.env][“database”] username = config[Rails.env][“username”] password = config[Rails.env][“password”] See the documentation for Rails::Configuration for details. This just uses YAML::load to load the configuration from the database configuration file (database.yml) which you can … Read more
$ sudo su $ env ARCHFLAGS=”-arch x86_64″ gem install pg Building native extensions. This could take a while… Successfully installed pg-0.11.0 1 gem installed Installing ri documentation for pg-0.11.0… Installing RDoc documentation for pg-0.11.0… WORKED!
$ sudo su $ env ARCHFLAGS=”-arch x86_64″ gem install pg Building native extensions. This could take a while… Successfully installed pg-0.11.0 1 gem installed Installing ri documentation for pg-0.11.0… Installing RDoc documentation for pg-0.11.0… WORKED!
NOTE: This doesn’t run the test via rake. So any code you have in Rakefile will NOT get executed. To run a single test, use the following command from your rails project’s main directory: ruby -I test test/unit/my_model_test.rb -n test_name This runs a single test named “name”, defined in the MyModelTest class in the specified … Read more
You could parse the response body like this: parsed_body = JSON.parse(response.body) Then you can make your assertions against that parsed content. parsed_body[“foo”].should == “bar”