gem-session.com

Where there was once a consistent API to manipulate and hook into the lifecycle of a persistent object, plugins must...

github.com

...outputs a Rack application which you can either serve standalone or mount into your Rails app...

.../etc/apache2/sites-enabled with something like the following ^ NameVirtualHost *:80 <VirtualHost *:80> ServerName application.local DocumentRoot /opt/application/public RailsEnv development RailsAllowModRewrite off <VirtualHost *:443> ServerName application.local DocumentRoot /opt/application/public RailsEnv development RailsAllowModRewrite off SSLEngine on...

etag { current_user&.id } etag { current_user&.updated_at } end Under the hood, Rails generates an ETag header value like W/"f14ce3710a2a3187802cadc7e0c8ea99". In doing so, all objects from that...

...etag { current_user&.updated_at&.to_f } end You might even want to patch Rails' etagging logic so you don't have to remember doing that. Here you go:

Empty CSPs with send_file If you use send_file from a Rails controller, you can send potentially dangerous files with an inline disposition iff you also send...

...would execute active content): Content-Disposition: attachment If you use send_file from a Rails controller, the default disposition is attachment. You can also set it explicitly: send_file @attachment.path...

makandra dev

Ruby 1.9.2 is very slow when loading files, especially starting Rails servers or running specs takes forever. Do yourself a favor and upgrade to...

When using form_for you can give the form's target URL either as a string or an array:

...runs; Code Reviews include test badge; Automatically merge a PR on green tests Upgrade Rails 5 0 - 5 New Rails features are accessible Replace slider framework 4 4

This is what worked for me in a Rails 4: # JSON data as first argument, then parameters patch :update, { some: 'data' }.to_json, id: id, format: :json

You might find that your Passenger ignores all RailsSomething directives in the vhost for your new Rails 3 application. The culprit is a file config.ru which makes Passenger consider your...

...application a Rack (non-Rails) application. To fix this you can either use RackEnv in lieu of RailsEnv (it works fine) or delete the config.ru. Unless you have a good...

end html end Full disclosure: Under the hood this uses the private Rails helper method split_paragraphs that simple_format uses. While it might break when upgrading Rails...

After switching to Rails 3 you may get a LoadError with the following message when trying to use your application via passenger: no such file to load -- dispatcher Your Passenger...

...comparison can often be seen with simple string comparison like so. # ❌ Not recommended if Rails.version > '6.1.7.8' || RUBY_VERSION > '3.1.4' raise Error, 'please check if the monkey patch below is still...

...comparison above works by coincidence. But chances are that you are not: For example, Rails version 6.1.10.8 would not raise an error in the code block above, because in an...

...up releases, not assets. In order to clean up assets, you can use capistrano-rails. Just require 'capistrano/rails' in Capfile and add the following config: # config/deploy.rb set :keep_assets...

...remove any older versions. If you are using Webpacker, you need to configure capistrano-rails. If you are on Rails 3, you cannot use this to clean up assets. :keep...

Accept: application/json This means the client will only understand JSON responses. When a Rails action is done, it will try to render a template for a format that the...

...pages/foo, application/foo with {:locale=>[:de], :formats=>[:json], :handlers=>[:erb, :builder, :haml]} This is because Rails tried to find a template like foo.js.erb but all it found was foo.html.haml (which the...

When you run rake db:create and get this error message Couldn't create database for {"encoding"=>"utf8", "username"=>"root...

makandracards.com

...config/initializers/searchkick.rb (or wherever you have configured your Searchkick settings) add: SEARCHKICK_CLIENT_TYPE = case Rails.env when 'production', 'staging', 'development', 'test' :elasticsearch else :opensearch end Searchkick.client_type = ENV.fetch('SEARCHKICK_CLIENT_TYPE...

...SEARCHKICK_CLIENT_TYPE).to_sym ENV['OPENSEARCH_URL'] ||= case Rails.env when 'production' OPENSEARCH_PRODUCTION_SERVER when 'staging' OPENSEARCH_STAGING_SERVER else 'http://opensearch:9200' # docker container name end

yehudakatz.com

Yesterday, there was a blog post entitled “What the Hell is Happening to Rails” that stayed at the number one spot on Hacker News for quite a while. The post...

...the comments on the post reflect deep-seated concern about the recent direction of Rails. Others have addressed the core question about change in the framework, but I’d like...

If you specify different ports, you can run multiple local webricks with rails server --port=300X at the same time...

makandracards.com

Rails applications and ruby gems should have a README that gives the reader a quick overview of the project. Its size will vary as projects differ in complexity, but there...

...be written atop the class file. Structure I suggest the following outline for a Rails project's README, using the very readable Markdown language: # App title Describe the whole project...

...a dump from db/production_structure.sql: class LoadDump < ActiveRecord::Migration def up config = YAML.load_file('config/database.yml')[RAILS_ENV].symbolize_keys config[:flags] = Mysql2::Client::MULTI_STATEMENTS client = Mysql2::Client.new(config) sql = File.read...

github.com

...all requests to a Rack application. You can use Sinatra, raw Rack, or even Rails as your application, allowing you to build up an equivalent to the remote service you...

...part is a bit lengthy, but it allows you to debug strange bugs with Rails autoloading the wrong constants. Due to the constant lookup rules above, Rails sometimes guesses wrong...

...in development and production, but the problem exist for both environment. Development During development, Rails unloads all classes after every request. This way code changes take effect immediately, without requiring...

...model validation that restricts its length. There are two motivations for this: In modern Rails, database types :string and :text no longer have a relevant size limit. Without a validation...

...malicious user can quickly exhaust the hard drive of your database server. In legacy Rails (or database schemas migrated from legacy Rails), database types :string and :text had a database...