...does not apply to your "Background" steps How to set up database_cleaner for Rails with Cucumber and RSpec Before all in database transactions will fail
...prevent this, you need to add ->{ uniq } as second argument to has_many (below Rails 4 it is a simple option: has_many :xyz, :uniq => true). Example
There is a way to use multiple databases in Rails. You may have asked yourself how you're able to keep your test databases clean, if you're running multiple...
...records to check if the migration works properly with those. after_initialize :readonly!, unless: -> { Rails.env.test? } end When defining multiple adapters in your database.yml, Rails needs to decide which one to...
...a lib/ext/super_client.rb to your project (see How to organize monkey patches in Ruby on Rails projects) Add the extension, which overrides both methods (prepend is available since Ruby >=2)
When your Rails application server raises error, Capybara will fail your test when it clears the session after the last step. The effect is a test that passes all steps...
...three ways to go. The same applies to files in Carrierwave. 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...
...have to either: Sort both the query and database content. If you're on Rails 7.1 you can use the new normalizes macro for this. This solution would still use...
...model. Prefer to use a form model like User::RegistrationForm. Read our book Growing Rails Applications in Practice for details. Here is a test for the User model that automatically...
...is to to require all files in a specific diretory, using something like Dir.glob(Rails.root.join('lib/ext/**/*.rb')).each do |filename| require filename end However, this causes files to be required...
...behavior on different machines which are hard to debug. Simply add a .sort: Dir.glob(Rails.root.join('lib/ext/**/*.rb')).sort.each do |filename| require filename end Ruby 3 Ruby 3 Dir class sorts...
...resources. The spec looks very similar to how one would build an API with Rails and uses similar patterns. Even if you don't plan on supporting the whole spec...
...for example could be sped up more than 4 times by reusing a cached Rails application, and the tests for a video player we built could also be sped up...
...ein User ungefiltertes HTML in die Webseite einfügen kann. Danke für den interessanten Beitrag! alert('you have been hacked') Rails löst das Problem weitgehend, aber Programmierfehler weiter möglich manchmal Sicherheitslücken in Gems oder Rails
background-color: blue; } = javascript_tag nonce: true do :plain window.addEventListener('load', () => { ... }); CSP mit Rails Demo Konfiguration via config/initializer/content_security_policy.rb Überschreiben in einzelnen Controllern Nonce-Support für javascript_tag
...popular authentication libraries like clearance or devise for this task. Learn Read the article Rails Authentication from Scratch You don't need to do write any code, but you should...
...you have access to the database? Can you sign out a user using the Rails console? If someone can read our network traffic, can he see a user's password...
...cloned project. The reason is your environment.rb which is loaded for Raketasks and calls Rails.application.initialize! which in turn may/will evaluate classes. If one of those classes is tries to access...
# ActiveRecord 3.2+ was activated end Detect if a gem has been required Rails will automatically require all the gems in your Gemfile, unless you pass the require: false...
...option. When working on non-Rails project (such as a gem), nothing is required automatically. To detect if a gem has been required, use defined? on one of the modules...
...if you don't know which one handled the request you are looking for. Rails application logs usually live in /var/www/ /shared/log. Web server logs usually live in /var/www/ /log...
...multiple servers at the same time With a custom Capistrano task: CMD='zgrep -P "..." RAILS_ROOT/log/production.log' bundle exec cap production app:run_cmd See Capistrano 3: Running a command on...
...command line flag when opening an IRB: irb --nomultiline This also works on modern Rails when using rails console like so: rails console -- --nomultiline Option 2: Disable by default
...into a database console, run SET GLOBAL query_cache_type=OFF; and restart your rails server. You can also disable the cache on a per query basis by saying
...SQL_NO_CACHE * FROM ... You also probably want to disable Rails internal (per-request) cache. For this, wrap your code with a call to ActiveRecord::Base.uncached. For example, as an...
When deleting a record in your Rails app, Carrierwave automatically takes care of removing all associated files. However, the file's container directory will not be removed automatically. If you...
...MySQL or PostgreSQL. Implementation examples are for the ActiveRecord ORM used with Ruby on Rails, but the techniques can be implemented in any language or framework. We will be using...
expect(time1).to eq(time2) end Note for users of #end_of_day Rails extends Time with a method #end_of_day which returns the latest possible Time on...
From Exploring ES6: Module imports are hoisted (internally moved to the beginning of the current scope). Therefore, it doesn’t...
YOUR QUERY\G; \x on Further reading How to setup Ruby on Rails with PostgreSQL Connect to a Rails database with bin/rails dbconsole -p...
...If you trigger a COUNT query for an association of an an unsaved record, Rails will try to load all children where the foreign key IS NULL. This is not...