Params are tricky Testing for request params is a little tricky because Rails hides details about how HTTP works. In particular GET requests encode their params in the URL...
...is good programming practice to Don't Repeat Yourself (or DRY). In Ruby on Rails we keep our code DRY by sharing behavior by using inheritance, modules, traits or partials...
...shell commands inside other bundles. Example outline Consider this setup: my_project/Gemfile # says: gem 'rails', '~> 3.0.0' my_project/foo/Gemfile # says: gem 'rails', '~> 3.2.0' And, just to confirm this, these are the...
...installed Rails versions for each of the bundles: ~/my_project$ bundle show rails .../gems/rails-3.0.20 ~/my_project$ cd foo && bundle show rails .../gems/rails-3.2.13 Now you will usually just use bundle exec to run...
...insert many records is to have a single INSERT statement describing multiple rows. In Rails 6+ you can do so with ActiveRecord::Base.insert_all. This is very fast, but you...
When a user shares your content, a snippet with title, image, link and description appears in her timeline. By default...
...twentieth in what ordering? The ordering is unknown, unless you specified ORDER BY. In Rails, if you use Record.first or Record.last, it will default to ordering by id.
...so that a tcp connection is used instead of a socket connection. Configure rails application to use the database development: adapter: mysql2 database: projectname_development encoding: utf8mb4 collation: utf8mb4_unicode...
...Fixtures are handy for development seed data, they can be loaded in development with: rails db:fixtures:load Downsides Less matchers & library support It is harder to mock with minitest...
...use a light terminal theme Improving Diffs for Ruby, RSpec and Cucumber files See Rails developers: Have better context in Git diffs. This will correctly identify the beginning of a...
...used to match rows without knowing a secret token: Potential Query Manipulation with Common Rails Practises CVE-2013-3211 MySQL madness and Rails
...delay of ~1 minute. Note: This setup does not work, when you use the Rails driven_by method with a binary preloading for parallel tests. CI Optionally you can use...
...your view might be too isolated, since view-specs will mock a lot of rails behavior and render the view independent from the controller-logic. Therefore it will be more...
...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|
...an alternative to PostgreSQL fulltext search A simple example with a GIN index in Rails for optimizing a ILIKE query
...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...
...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...
When using Rails to truncate strings, you may end up with strings that are still too long for their container or are not as long as they could be. You...
...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...
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...
...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...
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(...)
...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...
...our older projects, we use the mysql2 gem. Unfortunately, versions 0.2.x (required for Rails 2.3) and versions 0.3.x (required for Rails 3.2) can no longer be installed on...
...to errors when compiling the native extension, or a segfaults when using it. For Rails 4.2, mysql2 version 0.4.10 seems to work okay. If you still have issues, upgrade to...