docs.ruby-lang.org

...argument. Also, the code after the yield in example is not executed! Probably, this behavior was designed to enable programmers writing their own iterators (like while or loop) as methods...

makandra dev

...fixed. However, as your frontend adds more JavaScript, AJAX and animations, this test might become "flaky". Flaky tests destroy the trust in your test suite ("I thought this is always...

...before raising NoSuchElementError. This is sufficient for basic, server-rendered application. However, as frontends become more complex (more JavaScript, AJAX requests, animations), race conditions will become too severe to be...

makandra dev
makandracards.com

Rails applications and ruby gems should have a README that gives the reader a quick overview of the project. Its...

...crash your script. Either use if record.save, or wrap the respective code like this: begin # If using transactions, nest them here

...record.save! ... rescue ActiveRecord::RecordInvalid # Handle error end

makandra dev

In a Jasmine spec you want to spy on a function that is imported by the code under test. This...

...has attributes like these: class User < ApplicationRecord has_many :posts end class Post < ApplicationRecord belongs_to :user validates :user, presence: true # Default for belongs_to on Rails 5+ end

makandra dev

tl;dr git checkout is the swiss army of git commands. If you prefer a semantically more meaningful command for...

...instantly. CSS, JavaScript and the browser settings all have options to influence the scroll behavior. They all interact with each other and sometimes use the same words for different behavior...

Scrolling elements can use the scroll-behavior CSS property to express a preference between smooth and instant scrolling. Preferring instant scrolling CSS can prefer instant scrolling behavior: html {

Nowadays it is fairly easy to intercept and modify mails globally before they are sent. All you have to do...

Don't forget users with a slow internet connection. Not everyone is sitting behind a FTTH cable with warp speed. Throttle your browser's internet connection (e.g. in the...

...Chrome DevTools network panel) to feel how your app behaves. If you're using Unpoly, show a loading state while requests are loading. If you cannot implement this for every...

When you write your next CarrierWave uploader, consider processing your images with libvips instead of ImageMagick. Reasons for libvips

...nested form. See ActiveRecord: When aggregating nested children, always exclude children marked for destruction. Best practice example Here we will use what we learned above in order to create a...

To attach files to your records, you will need a new database column representing the filename of the file...

...it with a (lead) developer before it is ready. The backlog Every issue should begin its life in the icebox and only be moved to the backlog if it is...

...where_values_hash. This should be the least preferred option. Often times, you are better off using invert_where (if available), Arel or a subquery...

...to attach a timestamp or content hash to your asset's filenames, e.g. foo.png becomes foo-2179b43e243cf343.png. This way, when the asset changes, its URL changes. You can now safely tell...

...helper attaches an MD5 hash of the file content to the asset. E.g. /app/assets/foo.png becomes: /assets/foo-2179b43e243cf343.png These hashes will only be added when assets.digests is enabled for your environment (it...

...Most specs don't require you to define a class. Usually, you test the behavior of an existing class from your application. A common use case ist testing modules which...

...are included elsewhere. Your module may behave differently depending on the including class, be parameterized (like with Modularity), or just offer an API (e.g. has_defaults) that you want to...

When projects run for many years, they require special regular maintenance to stay fresh. This kind of maintenance is usually...

You have uncommited changes (you can always check by using git status), which you want to discard.

en.wikipedia.org

...the redirect. It is preferrable to use the newer status code to avoid unexpected behavior. 303 See Other The response to the request can be found under another URI using...

...all future requests should be repeated using another URI. 307 and 308 parallel the behaviors of 302 and 301, but do not allow the HTTP method to change. So, for...

RubyMine comes with a nice way to grep through your project's files: The finder (ctrl + shift + f). Don't...

When you repeat a subpattern with a *, + or {...} operator, you may choose between greedy, lazy and possessive modes. Switching modes...

...use ActionDispatch::RemoteIp use Rails::Rack::Logger use ActionDispatch::ShowExceptions use ActionDispatch::DebugExceptions use BetterErrors::Middleware use ActionDispatch::Reloader use ActionDispatch::Callbacks use ActiveRecord::Migration::CheckPending use ActionDispatch::Cookies

When a user shares your content, a snippet with title, image, link and description appears in her timeline. By default...