Since Rails 6+ you can use before? and after? to check if a date/time is before or after another date/time. Example christmas = Date.parse('24.12.2022') date_of_buying_a...
The benefit of the Rails asset pipeline is that it compiles your stylesheets and javascripts to a single file, respectively. However, the consequences are startling if you don't understand...
...gave every library its own "root" folder. First, add this line to your config/initializers/assets.rb: Rails.application.config.assets.paths += Dir["#{Rails.root}/vendor/asset-libs/*"].sort_by { |dir| -dir.size } This will tell Rails about the custom asset...
To read the Rails session from a Rack middleware, use env['rack.session']. It's an ActionDispatch::Request::Session object. class MyMiddlware def initialize(app) @app = app end def call(env...
...status, headers, body = @app.call(env) session = env['rack.session'] Rails.logger.info("Value of session['foo'] is: " + session['foo'].inspect) [status, headers, body] end end You may not be able to write to...
If your irb or rails console keeps randomly crashing and you can't figure out why then you can try to disable multi-line autocomplete...
...a situation in which I received the yarn integrity check warning when starting the rails console even though everything was up to date and correct versions in use.
I tried starting the rails console without switching to the correct node version first and received the yarn integrity warning. warning Integrity check: System parameters don't match...
...Gruff for easily plotting graphs. It is written in pure Ruby and integrates with Rails applications. It provides features as automatic sizing of dots and lines (the more values, the...
...restart your development server.) Usage This is a common example for graph generation in Rails. Note that you have many configuration options at hand that are not documented. Github and...
To ensure Spring is not running: bin/spring stop pkill -f spring To prevent Spring from starting again: export DISABLE_SPRING...
Starting from Rails 4.0, you can use a special form options helper called #collection_check_boxes. It behaves similar to #collection_select, but instead of a single select field it...
Note the hidden input at the end. This is a trick that Rails uses so users can uncheck all the check boxes. If this hidden input wasn't...
You can use record.send(:update_without_callbacks) or record.send(:create_without_callbacks) This can be used as a lightweight alternative to machinist's make or FactoryGirl's create...
...return the object, so you might want to do record = Record.new.tap(&:create_without_callbacks) Rails 3 Rails 3 no longer comes with update_without_callbacks or create_without_callbacks. There...
The linked content includes a few design patterns implemented with Ruby on Rails. What is the card indented to achieve? You can use the pattern names for code reviews, so...
} } } } } Integration in Rails + searchkick Was benötigt man für Integration von Elastic in eine Rails-Anwendung? Mindestens: Client um mit Elastic zu reden Erzeugen von Indexen, passender Mappings + Migration...
The author describes his little journey in hunting down a memory leak. Maybe his approach and tooling may one day...
Create, or edit your ~/.irbrc file to include: require 'irb/ext/eval_history' # was 'irb/ext/save-history' for versions prior to Ruby 3.3 IRB.conf[:SAVE...
Sometimes you want to have a time in a given timezone independent from you Rails timezone settings / system timezone. I usually have this use case in tests. Example
...return different results e.g. 2020-08-09 00:00:00 +0200 depending on the Rails timezone settings / system timezone. But in this example we always want to have the given...
...reload the page, log into the site and reload the cookie information site. For Rails powered sites, you should see a cookie named '_your_site_session' and -- depending on your...
...SHA:EDH-RSA-DES-CBC-SHA:EDH-DSS-DES-CBC-SHA | To make your Rails application use SSL, modify config/database.yml and add this: sslca: /path/to/mysql-ssl-ca-cert.pem Ensure only encrypted connections are...
...writing a piece of reusable code, you sometimes need to have separate code for Rails 2 and Rails 3. You can distinguish between Rails versions like this: if Rails.version...
...mind the quotes # Rails 2 code goes here else # Rails 3+ code goes here
Rails defines a #truncate helper as well as a method String#truncate. = truncate("my string", length: 5) = "my string".truncate(5) Both are really similar; in fact, the helper invokes...
...concept worked really good. Here are two points that were extraordinary compared to normal Rails project with many UI components: Having a Rails application, that has no UI components (only...
...to look up different before you need to integrate an API component into your Rails application. REST API vs. GraphQL It is worth to consider whether you want to have...
...capable of caching images. (FYI, here's how to do the upload all manually.) Rails setup Build these models: class Gallery < ActiveRecord::Base has_many :images, dependent: :destroy accepts_nested...
...connect a record to an already uploaded file = image_form.hidden_field :file_cache # Used by Rails to distinguish new from existing records = image_form.hidden_field :id # Used by Rails to know when...
The information in this card is only relevant for Rails 2.3-era apps. This note gives a quick introduction into caching methods (page caching, action caching and fragment caching) in...
...rails and describes some specific problems and solutions. The descriptions below are valid for Rails 2 and 3. Recently, caching with timestamp- or content-based keys has become more popular...
...decide to open a file directly instead of having to save it first. For Rails >= 3.2 Simply put your mime types in config/initializers/mime_types.rb. send_file will take care of everything...
For Rails < 3.2 Put your mime types in config/initializers/mime_types.rb. Additionally, tell send_file to use them (for example like this): file = @attachment.file.path file_extension = File.extname(file)[1..-1]
When logging in Rails, you can use the log_tags configuration option to add extra information to each line, like :request_id or :subdomain. However, those are only valid inside...
...log entries which are mixed together. Welcome to debugging hell. You want something like Rails' :request_id tagging. This can easily be achieved through a Sidekiq middleware as follows.
Specify these gem versions in your Gemfile: gem 'cucumber', '~> 1.3.0' gem 'cucumber-rails', '= 0.3.2' # max version for Rails 2 gem 'capybara', '< 2' # capybara 2+ requires Rails 3 gem 'mime-types...