Adopting legacy Rails apps Talk to your mentor about how we're approaching applications that are either old or abandoned by a different team earlier: Add E2E tests for the...

Rails' ActiveSupport::TimeWithZone objects have both a timezone code and offset, e.g. Thu, 28 Mar 2019 16:00:00 CET +01:00. Ruby's stdlib TZInfo also has time zones...

...chances are you'll end up in the wrong time zone. This is why Rails actually uses a long list of time zone names with have names like "London" or...

...Probably the best approach is to just convert emails (and usernames) to lowercase within Rails. Popular authentication libraries (like Clearance and Devise) already do this for you...

This RailsCast demonstrated a very convenient method to activate VCR for a spec by simply tagging it with :vcr. For RSpec3 the code looks almost the same with a few...

...vcr and webmock gems installed, simply include: # spec/support/vcr.rb VCR.configure do |c| c.cassette_library_dir = Rails.root.join("spec", "vcr") c.hook_into :webmock end RSpec.configure do |c| c.around(:each, :vcr) do |example|

...application server without configuration Usage Install Passenger Standalone with gem install passenger Inside any Rails project, start Passenger Standalone with passenger start Alternatives You can use Puma. It also supports...

...allows you to log to multiple sinks. You know this behavior from from the rails server command, that both logs to standard out and the log/development.log file.

...development.log file. Here is an example for Sidekiq: Sidekiq.configure_client do |config| if ENV['RAILS_ENV'] == 'development' || ENV['RAILS_ENV'] == 'test' stdout_logger = ActiveSupport::Logger.new(STDOUT) file_logger = ActiveSupport::Logger.new...

} start your server as usual, but go to https://localhost:3000 bundle exec rails s Accept the certificate in your browser See also Creating a self-signed certificate for...

...deployed to the servers. The gems of these groups might not be loaded by rails, however, the deployment process will take longer as the gems will be downloaded and installed...

JavaScript files that can be loaded individually from your application layout. By default your Rails application has a single entrypoint application.js, which should import all other files.

kernel.org

...mind that you may need to migrate your database as Git is unaware of Rails and will not cast any magic. If Git checked out a commit that is working...

stackoverflow.com

To reload a single-item association in Rails 5+, call #reload_ : post.reload_author In older Railses you can say post.author(true...

github.com

...ETag for responses that only differ in CSRF tokens or CSP nonces. By default Rails uses Rack::ETag to generate ETag headers by hashing the response body. In theory this...

...would enable caching for multiple requests to the same resource. However, since most Rails application layouts insert randomly rotating CSRF tokens and CSP nonces into the HTML, two requests for...

...excludes quote characters so you can easily paste the secret into a Ruby string Rails can also generate secrets that can be used for secret_key_base: $ bin/rails secret 5693040b90b1b09d0a73364d950f15e3a9604403c8e81c6e5bb8b51d0981ef3bbde15a52bf5df41ac4974675bb8e31d69d03490dc11abd1086c873783d1be607

...create only the records needed for the test. Learn Factories, not fixtures By default Rails uses global fixtures for its tests. This is a giant world of example data that...

...other gems in the past, but they all work in the same way. Watch Railscasts PRO #158 Factories not Fixtures (revised) for an introduction to factories in general and FactoryBot...

geekytidbits.com

ORDER BY category DESC, created_at; The easiest options to achieve this in Rails ActiveRecord is to use "WHERE ID IN" with User.where(id: Post.distinct_on_user.pluck(:user_id)).order(...)

...README for the carrierwave gem Read about Common mistakes when storing file uploads with Rails Carrierwave: How to attach files in tests Carrierwave: Built-in RSpec matchers CarrierWave: Processing images...

...The following setup allows you to start Terminator in a split view with the Rails server running in the left pane and all remaining processes running via foreman in the...

type = Terminal parent = child1 profile = default command = env startup_cmd="bundle exec rails server" startup_attrs="-p 3000" bash [[[terminal3]]] type = Terminal parent = child1 profile = default command = 'env startup...

Understand that each call of a cron job will boot up your Rails application and produce 100% load on a CPU during booting. Talk to your mentor what...

linux.die.net

...also use Cookies with cURL. For easily making HTTP requests in an IRB or Rails console, take a look at the HTTP gem. If you prefer a GUI, take a...

...we still recommend the solution in this card. If you need to synchronize multiple rails processes, you need some shared resource that can be used as a mutex. One option...

haml.info

%span Reference %pre ~ content Reference Hello World Textareas In some versions of Haml + Rails, this may also be an issue for textarea elements. Fix it similarly: # Indented description

...notably, it allows you to represent data in a very readable manner. For example, Rails offers a compact DSL to define new routes. A big drawback however is that your...

...generated for associations. Warning Don't use query_attribute on associations. In case of Rails 7 you are getting an error. In Rails 6 this method is always responding with...

Use gem 'mysql2', git: 'https://github.com/makandra/mysql2', branch: '0.2.x-lts' # for Rails 2.x gem 'mysql2', git: 'https://github.com/makandra/mysql2', branch: '0.3.x-lts' # for Rails...