If you want to make your Rails application be capable of sending SMTP emails, check out the action mailer configuration section in the Ruby on Rails guide.
...in your environment or individually applied to an email generated in your mailer: # production.rb: Rails.application.configure do config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = smtp_settings end # test_mailer.rb def test_mail
...page for more information on calculating sizes of databases or tables. Connect to a Rails database with bin/rails dbconsole -p...
...code is causing an exception which is not the one shown in your terminal. Rails tries to catch this exception and clean up constants but -- while it's still booting...
Have a look at the environment's log file instead Open up a Rails console (may give you more information than the logs) If you're lucky it's...
Rails comes with a Rake task notes that shows code comments that start with "TODO", "FIXME", or "OPTIMIZE". While it's generally not good practice to leave them in your...
app/helpers/frontend/slider_helper.rb: * [48] [TODO] this is only temporary till frontend is done However, with Rails' default configuration this task will only look through default file extensions, like .rb, .erb, .css...
...for easily adding new commands many little niceties New commands setup: set up a Rails project for the first time (bundle install, create database.yml, create databases, migrate), optionally run all...
...update by pulling/pushing/merging and deploying just as our workflow is devserver: boot a development server Rails-version-agnostic console: open a local Rails console Rails-version-agnostic, or remotely, e.g...
After upgrading to Rails 6.1.7.2 one of our apps printed a wall of warnings while booting: /var/www/app/shared/bundle/ruby/2.6.0/gems/net-protocol-0.2.1/lib/net/protocol.rb:68: warning: already initialized constant Net::ProtocRetryError /home/deploy-app/.rbenv/versions/2.6.10/lib/ruby/2.6.0/net/protocol.rb:66: warning: previous definition of...
...is to "vendor" the gem by copying it into the vendor/gems directory of your Rails project. You can then make any changes you require and Rails will use the vendored...
...after a server restart. Unfortunately you need to perform some additional steps to marry Rails and the copied gem. This notes describes what to do. With Bundler
tl;dr: Always have your attachment path start with :rails_root/storage/#{Rails.env}#{ENV['RAILS_TEST_NUMBER']}/. The directory where you save your Paperclip attachments should not look like this: storage/photos/1...
...storage/test/photos/1/... storage/test/photos/2/... storage/test/attachments/1/... storage/test/attachments/2/... storage/test2/photos/1/... storage/test2/photos/2/... storage/test2/attachments/1/... storage/test2/attachments/2/... In order to implement this, make Rails.env and ENV['RAILS_TEST_NUMBER'] part of your path template: has_attached_file :attachment, :path...
...the standard configuration, though, it does not interpret the escape sequences used in the rails logfiles. To enable this type: less -R my_logfile.log You can also have an alias to...
...they won't change their mind. [1] We are not talking about the the Rails session cookie here, though it often is a session cookie...
...repositories. It's basically "Open Source Development 101". Way back in mid-2007, when Rails 1.2 was the new hotness and GitHub was still a year away from crawling out...
Test one codebase against multiple sets of gem dependency sets (e.g. Rails 4.2, Rails 5.0). Test one codebase against multiple Ruby versions (e.g. Ruby 2.1.8, Ruby...
...possible dependency permutations (Ruby, gem set, database type). Manually exclude incompatible dependency permutations (e.g. Rails 5.0 does not work with Ruby 2.1). Let developers enter their local credentials for MySQL...
The ActionDispatch module of Rails gives you the helper method flash to access the flash messages in a response. describe PostsController, type: :request do describe 'update' do it 'shows a...
...them, this is fortunately made very easy if you use compass. Simple example for Rails 3+ Let's assume you have two images app/assets/images/layout/blue-button.png, and .../blue-button-hover.png and the following sass...
...not there already, add this to the :assets group in your Gemfile: gem 'compass-rails' gem 'oily_png' Run bundle install. Add a config/compass.rb with the following content:
...see below) -- but can be a problem, for example for the capture method of Rails. Consider these methods: def stuff puts 'yielding...' yield puts 'yielded.' true end
...have probably seen it before, e.g. a return in an each block. Impact on Rails applications Since this is something that you would have to do yourself, you could just...
...helps to modify the Accept-Language in tests. Here is an example for a Rails application with Cucumber integration tests: class ApplicationController OVERRIDE_HTTP_ACCEPT_LANGUAGE = nil def accept_language...
...t like an ActiveSupport::HasWithIndifferentAccess. There are also some issues if you are on Rails < 4.1 and want it to replace #to_json (but you can always just call Oj.dump...
What I did test successfully was the workaround below. Workaround In Rails 4 you can wrap the output of Oj.dump(...) in an escape_json tag to escape...
...not doing this. Use form models or vanilla methods instead. The :conditions option for Rails associations cannot take a lambda. This makes it hard to define conditions that must be...
...a typo. It's to prevent Ruby from interpolating the string at compile time. Rails is aware of this hack and will perform interpolation at runtime. See this article for...
...tokens or CSP nonces. We have deprecated Rack::SteadyETag. We instead recommend reconfiguring your Rails app so two requests to the same resource produce the same HTML for a given...
.../../../../../../../../../etc/passwd%%0000.html) Someone tries to exploit CVE-2019-5418. If you use the latest Rails (or latest Rails LTS) you're safe. The exact versions that fix this issue are...
...Rails 6.0.0.beta3, 5.2.2.1, 5.1.6.2, 5.0.7.2, 4.2.11.1, Rails LTS 3.2.22.13 and Rails LTS...
...groups are a useful RSpec feature. Unfortunately the default directory structure generated by rspec-rails has no obvious place to put them. I recommend storing them like this: spec/models/shared_examples/foo.rb spec/models/shared_examples/bar.rb...
...those shared examples available to all specs, put the following into your spec_helper.rb (for rails 4 in rails_helper.rb), above the RSpec.configure block: Dir[Rails.root.join("spec/models/shared_examples/**/*.rb")].each {|f| require f...
...byebug 11.1.3 (the most recent version at time of writing) when using it with Rails 6 and it's new autoloading component, zeitwerk. There already is a issue for that...
Rails includes milliseconds in Time / DateTime objects when rendering them as JSON: JSON.parse(User.last.to_json)['created_at'] #=> "2001-01-01T00:00:00.000+00:00" In RSpec you might want...
If your rails application is unable to send mails, it might be useful to debug your settings using the rails console. Here is a snippet that shows the current settings...