Info on install database_cleaner.
It occurred to me that many Rails/Passenger/Apache applications may have caching set up in a way that it appears to be caching, when it is not actually caching...
Where there was once a consistent API to manipulate and hook into the lifecycle of a persistent object, plugins must...
...outputs a Rack application which you can either serve standalone or mount into your Rails app...
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:
...sure not to mess with that. Related cards If you are using Ruby on Rails, a use case / implementation might look like Rails 3: Sending tempfiles for download.
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:
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
The same applies to files in Carrierwave. Variant: Deliver attachments through Rails The first way is to store Paperclip attachments not in the default public/system, but in...
...can be configured like this: class Note < ActiveRecord::Base has_attached_file :attachment, :path => ":rails_root/storage/:rails_env/attachments/:id/:style/:basename.:extension" end To link to the protecting controller actions...
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...
...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...
...can never change them without forcing users to empty their cache. Note By default Rails sends a header Cache-Control: max-age=0, private, must-revalidate with all responses, including...
...cached by browsers. You do need to pay attention if you redirect outside of Rails, e.g. via your web server configuration. Dealing with incorrectly cached redirects The only fix is...
When you run rake db:create and get this error message Couldn't create database for {"encoding"=>"utf8", "username"=>"root...
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...
.../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...
...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...
...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
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...
...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...