github.com

When you need to use diff in either some Ruby code or your Rails app, use the differ gem. puts Differ.diff "foo", "boo" # => {"boo" >> "foo"} Usage There are several variants...

Expiration of Rails sessions By default Rails sessions expire when the user closes her browser window. To change this edit your config/initializers/session_store.rb like this: ActionController::Base.session = { :key => '...', :secret => '...' :expire_after...

} In older Railses the initializer is not available. Set the option in the environment.rb instead: config.action_controller.session = { :key => '...', :secret => '...' :expire_after => 10.years } Expiration of Rails cookies In addition to the...

...echo the environment setting in our application layout: <%= tag :meta, name: 'feature:polling', content: Rails.configuration.feature_polling %> Now polling is disabled by default for all tests. Our test suite has immediately...

...scenario 'The project list is updated periodically' do # Enable polling for this test allow(Rails.configuration).to receive(:feature_polling).and_return(true) # Go to the projects index and see an...

This only works when you actually have a session ID (not the case for Rails' CookieStore, for example): request.session_options[:id] # => "142b17ab075e71f2a2e2543c6ae34b94" Note that it's a bad idea to...

stackoverflow.com

...code is causing an exception which is not the one shown in your terminal. Rails tries to catch this exception and clean up constants but -- while it's still booting...

Have a look at the environment's log file instead Open up a Rails console (may give you more information than the logs) If you're lucky it's...

makandra dev
github.com

...for easily adding new commands many little niceties New commands setup: set up a Rails project for the first time (bundle install, create database.yml, create databases, migrate), optionally run all...

...update by pulling/pushing/merging and deploying just as our workflow is devserver: boot a development server Rails-version-agnostic console: open a local Rails console Rails-version-agnostic, or remotely, e.g...

gist.github.com

When you encouter an unsafe string that you actually made html_safe before, perhaps you called one of the following...

Since Rails 5, domain models inherit from ApplicationRecord by default. This is the place to put code that should be available in all your application's models.

If you want to make your Rails application be capable of sending SMTP emails, check out the action mailer configuration section in the Ruby on Rails guide.

...in your environment or individually applied to an email generated in your mailer: # production.rb: Rails.application.configure do config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = smtp_settings end # test_mailer.rb def test_mail

Note that you cannot currently use Ruby 1.9.2 with Rails 2 applications that use RSpec, so don't upgrade if that is your setup. The rspec-rails gem has a...

...fatal bug that was only fixed for rspec-rails-2.x, which only supports Rails 3. There is no fix for the rspec-rails-1.3.x series of the gem...

makandra dev

The Rails asset pipeline improves delivery of application assets (javascripts, stylesheets, images, fonts). Here are some basic facts about its inner workings. No magic Manifests are the handle on your...

...results. You can do this locally using the following commands: rake assets:precompile # precompiles to Rails.root/public/assets rake assets:clobber # deletes the public/assets directory After precompilation, you can check the...

redmine.org

Phillip Koebbe from Ruby on Rails suggested inserting following code between the "bootstrap" and "initialize" sections of enviroment.rb. This hack fixes the problem. if Gem::VERSION >= "1.3.6" module Rails

Rails supports alert and notice as default flash types. This allows you to use these keys as options in e.g. redirect_to and as a helper in views e.g. <%= notice...

To check the currently running PG version from your Rails application (e.g. Rails console on your production server), simply do this: ActiveRecord::Base.connection.select_value('SELECT version...

github.com

...t like an ActiveSupport::HasWithIndifferentAccess. There are also some issues if you are on Rails < 4.1 and want it to replace #to_json (but you can always just call Oj.dump...

What I did test successfully was the workaround below. Workaround In Rails 4 you can wrap the output of Oj.dump(...) in an escape_json tag to escape...

If Rails or Rake are complaining about a missing gem that is listed in your Gemfile.lock and the listed version is properly installed, something is seriously wrong and needs to...

...seeing the gems it needs. Remove those wrong and unneccesary directories and Rake and Rails will boot again. To avoid this in the future, make sure everybody installs gems on...

...not doing this. Use form models or vanilla methods instead. The :conditions option for Rails associations cannot take a lambda. This makes it hard to define conditions that must be...

...a typo. It's to prevent Ruby from interpolating the string at compile time. Rails is aware of this hack and will perform interpolation at runtime. See this article for...

...migration_user.phone ) end end end Now the best idea is to test this in the rails sandbox (so your development data stay untouched): rails console --sandbox 2.4.1 :003 > DataMigration.new.run

...exceptions, maybe some bot visits your site requesting silly formats like: http://www.rails-app.com/makandra.html-username-2000 # => Rails tries to retrieve 'makandra' with format 'html-username-2000' Just restrict accepted format parameters for...

...not_acceptable) end end end end Note: request.format more reliably tells the format, but includes Rails-required formats such as application/x-www-form-urlencoded (which we must not refuse). For our purposes, getting...

This might eventually be fixed by Rails itself.\ Right now this is the way to have the rails_xss plugin not escape the body of ActionMailer mails.

...more unreadable to more attributes you delegate. Alternative to def_delegators When working with Rails, use delegate...

...:to =>...

class Post < ActiveRecord::Base belongs_to :topic delegate :title, :category, :to...

end Looks a lot like the above def_delegators call but behaves differently. Rails does not provide a pretty solution to this, but simply write a method for it...

You want Spring for super-fast binstubs like bin/rails or bin/rspec which avoid Rails boot time. You want parallel_tests to speed up full test runs of large test suites...

...not an issue for full test runs that take several minutes, we can accept Rails booting a few seconds. In your binstubs, there should be something like this: begin

Firefox 5.0.1, which we were using for most Rails 2.3 projects, does not run on Ubuntu 14.04 any more. Here is how to update affected projects. Update (or create) .firefox...

...run tests with Geordi, it will tell you how to install it. On a Rails 2 project: Update your Cucumber-related gems as described in Upgrading Cucumber and Capybara, including...

The following code activates autoloading using ActiveSupport 3.x: require 'active_support' require 'active_support/dependencies' relative_load_paths = %w[app/controllers...