...accidentally translates the query. It might be a good idea to cache the result (Rails.cache) for some time so a page reload doesn't re-call the LLM. Authorize the...

...to Hybrid search for the trade-offs, or How to add RAG to your Rails application to get started on the vector branch...

justinfrench.com

If you’re testing the behavior of deprecated code in your Ruby project, the warning messages littered throughout your spec...

gist.github.com

The differences are subtle. You probably want to use Time, except when you want to use DateTime. See the attached...

...Always convert to a symbol, otherwise you'll have all kinds of fun. Newer rails / activerecord (at least 5.2) will throw an association names must be a Symbol (ArgumentError) error...

...few examples, where you configure some library via a block. One example is the Rails configuration: Rails.application.configure do |config| config.enable_reloading = false end This card describes a simple example on...

...You can use ActiveSupport::Configurable instead of the Configuration class. When you are using Rails with Zeitwerk and the code for e.g. FooClient lives in a folder, that is loaded...

sudo apt-get install unzip rake rails:freeze:edge RELEASE...

...up repetitive expectations in your specs. Unfortunately the default directory structure generated by rspec-rails has no obvious place to put custom matchers or other support code. I recommend storing...

...to all specs, put the following into your spec_helper.rb, above the RSpec.configure block: Dir[Rails.root.join("spec/support/**/*.rb")].sort.each {|f| require f} Also see where to put shared example groups...

...already shipping as custom elements For example Trix from Basecamp (integrated as ActionText in Rails 6). By choosing custom elements as their delivery method, they work in all JavaScript frameworks...

...alotting time. This is a refactoring similar to removing resource_controller (but not a Rails upgrade). Grep for $. This will show you all the affected lines of code. Refactor functions...

...the same object. You also know that you can reload an association to make Rails load its data from the database again. user.posts.reload # discards cache and reloads and returns user.posts...

...reset returns the association/scope. Hence, the above will not seem to work on the Rails console, just because the return value is inspected and thus resolved right away.

When your Rails controller action responds with only a simple text, render text: 'Hello' may not be what you want. You should not even use it on Rails 4.1+ any...

By default, a "text" response from a Rails controller will still be a sent as text/html: render text: 'Hello' response.body # => "Hello" response.content_type # => "text/html" While this may not be...

github.com

Zeitwerk is the new autoloader of Rails. It is mandatory starting with Rails 7.0. Sometimes, a model needs to know all its descendants. They might be organized in a subdirectory...

...needs to iterate all design subclasses. To eager load all designs, use this line: Rails.autoloaders.main.eager_load_dir(Rails.root.join 'app/models/design') Make sure that app/models/design.rb is not required manually before instructing Rails...

makandra Curriculum

...piece, but it should be tidy and clear. If you have generated styles from Rails scaffolding, delete them all. They don't look nice and we do not use them...

...remove it and build your own styles from scratch. Tip Up until version 6, Rails understands Sass out of the box. No need to install additional software. Your MovieDB uses...

makandra dev

...point over a separate ClassMethods module inside of your module. If you are using Rails (or only ActiveSupport), you may also use ActiveSupport::Concern which facilitates this for you.

...taken in chronological order, you get this: Singleton class Class Included modules Superclass(es) Rails 5 introduced prepended modules which allow you to patch methods in a class in a...

Rails ships with two separate build pipelines: Sprockets ("asset pipeline") and Webpacker. Webpacker has many more moving parts, but allows us to use ES6 modules and npm packages (through Yarn...

github.com

RSpec.configure do |config| config.include Aegis::Matchers end In very old versions of Rails and RSpec you need to do this instead: ActiveSupport::TestCase.send :include, Aegis::Matchers

...stack of tools. Start this card by skimming over the linked resource. Discussion Growing Rails applications in practice Read the following chapters from our book Growing Rails Applications in Practice...

...On following fashions Surviving the upgrade pace of Rails Owning your stack Discuss each chapter with your mentor. The Swinging Pendulum The XKCD about the sandboxing cycle is quite on...

...BEM, block-by-block. Read Read the chapter "Taming Stylesheets" from our book Growing Rails Applications in Practice (in our library). Talk with a colleague about the reasons for the...

...a good BEM structure in the DOM tree of these websites: https://makandra.de/ https://railslts.com/ https://www.aitiraum.de/ Practice: Cards In a new project, try to layout the style of...

The Rails secret_token must be unique for each application and any instance of it. If not, someone could exploit this by creating a user with ID = 1 (e.g. on...

...current production users, leaving the production token unchanged: prefix the existing secret_token with #{Rails.env unless Rails.env.production?}. Note: There may be tokens in single quotes that include backslashes, double quotes...

Rails Active Support provides some helpful methods for calculating times and dates, like Duration#ago or Duration#from_now. But beware when using those, because they wont give...

...timezone unaware. Moreover, you have to be aware that ActiveSupport::TimeWithZone does not use Rails.application.config.active_record.default_timezone, which you need to define, even if you only use your local timezone, but...

...check Nokogiri::VersionInfo.instance.warnings for any warnings (though they should appear e.g. when launching a Rails console) or Nokogiri::VersionInfo.instance.to_hash to view more information. Note If your application uses Spring...

...collectiveidea.com/blog/archives/2012/01/27/testing-file-downloads-with-capybara-and-chromedriver module DownloadHelpers TIMEOUT = 10 module_function def download_path download_path = Rails.root.join("tmp/test_downloads#{ENV['TEST_ENV_NUMBER']}") FileUtils.mkdir_p(download_path) download_path end def clear_downloads FileUtils.rm...

makandra dev

# Redis db#1 is used for development. db_number = 1 if rails_env == 'test' normalized_test_number = [ENV['TEST_ENV_NUMBER'].to_i, 1].max db_number += normalized...

end db_number end def port case rails_env when 'staging' # when 'production' # else 6379 # default Redis port end end def rails_env defined?(Rails) ? Rails.env : ENV['RAILS...

shopify.com

Most web applications contain several examples of state machines, including accounts and subscriptions, invoices, orders, blog posts, and many more...

devblog.imedo.de

XPath matchers can be combined with CSS-selector matchers. This is really useful if not, for example, the content of...