} } } } } 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...
...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...
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 author describes his little journey in hunting down a memory leak. Maybe his approach and tooling may one day...
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...
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...
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...
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.
...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
tl;dr: Upgrade the gem to at least 4.0.1 When you use rspec_rails in a version < 4 with Rails 6.1 you may encounter an error like this: Failure/Error:
...expect(actor).to be_valid end end But the error came from rspec_rails itself. I found this issue on GitHub, which is solved in rspec_rails 4.0.1.
...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...
Rails 5.2+ supports "verbose query logs" where it shows the source of a query in the application log. Normally, it looks like this: User Load (0.5ms) SELECT "users".* FROM...
...While there was an issue back in 2018 which can be resolved by upgrading Rails, this also happens when ActiveSupport's BacktraceCleaner is configured to not hide gems from the...
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]
If you use webpacker in your Rails application, and you have completely disabled Sprockets, you might get the following error when trying to deploy: Rails assets manifest file not found...
...This happens inside the deploy:assets:backup_manifest task. This task comes from capistrano-rails. It is build for Sprockets and does not work with Webpacker out of the box...
To offer files for download, use send_file. def download(file) send_file file.path, :disposition => 'attachment' end
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...
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...
When working with times and dates in Rails applications, you need to deal with the following problem: In Rails, Time objects have a time zone. You can get the zone...
...just stores the literal string "2010-05-01 12:00:00". That means that Rails must make assumptions about timestamps loaded from and written to MySQL. Rails has two completely...
...and install RubyGems yourself. Install Bundler sudo gem install bundler Put bundler on a Rails 2.3 project Follow the instructions on bundler.io You should have patched your boot.rb
...reads Gemfile and builds Gemfile.lock with all dependencies etc. If you see "Missing the Rails 2.3.8 gem." you forgot to bundle Rails. If you see "Missing the mysql gem", bundle...
The Rails logger will store its content in a buffer and write it into the file system every 1000 lines. This will come back to bite you when using Rails.logger.info...
...environments auto_flushing is set to write after each line. On production environments the Rails logger writes only every 1000 lines -- and not upon shell or script termination as you...