mitrev.net

...false (intercepts invocation), whereas false&.class permits the invocation. &. might also remind you of Rails' Object#try. However, their scopes are different, and in Rails 4 nil-checking is only...

...add ANSI color annotations (which your console then interprets). To print a log (e.g. rails log) and color all lines containing "FATAL" in red and all lines with "INFO" in...

...often times the results of such subtractions go into a view. When upgrading a Rails application from Ruby 1.8 to 1.9, this will cause significant pain, and under most circumstances...

...cache_or_resolve :var, :some_expensive_calculation end This is what "memoize" in earlier rails versions did. There is a gem that reintroduces this behavior, but this is the essential...

tenderlovemaking.com

...for your application's bit of metaprogramming. It may matter for a framework like Rails, and for methods that are called really often, but that is not your everyday code...

...for when you can use transactions: Transactions cannot be used for Selenium features, where Rails and test run in different processes and thus don't see changes within the transaction...

...different cleaning strategies I measured the runtime of different strategies using an average-sized Rails project (with MySQL): Cucumber RSpec Transaction 87.14, 86.65 10.20, 10.11

Issue: You have an app using jsbundling-rails and esbuild. After deploy, the assets built by esbuild are missing in public/assets. Solution: Add app/builds to your git repo (by adding...

Rails has the handy controller method send_file which lets us download files easily. We can decide whether the file should be downloaded (disposition: 'attachment') or shown in the browser...

...use it anyway, learn the lessons we already learnt: Use a compatible Rubygems for Rails 2.3 on Ruby 1.8.7 Ruby 1.8.7 is not compatible with current Rubygems versions (> 2.0). Runnig...

...Keep in mind that this will not affect processes that are invoked through the Rails console. Put the environment variables into the user's shell configuration (e.g., ~/.bashrc) if you...

...column" ASC NULLS FIRST Your indexes will have to specify this as well. In Rails, declare them using add_index :table, :column, order: { column: 'DESC NULLS LAST' } Multiple columns

...need to represent later time values, use the DateTime class. This is also what Rails does when it loads a record from the database that has a DATETIME value which...

ActiveModel::Errors is used to handle validation errors on Rails objects. If you inspect an instance, it feels like a hash (to be more precise, it inherits from Hash):

ombulabs.com

...49/65) travis-lint... Slow requires: 110.21 render_anywhere 147.33 nokogiri 173.83 haml 179.62 sass-rails 205.04 delayed_job_active_record 286.76 rails 289.36 mail 291.98 capistrano 326.05 delayed_job...

...Otherwise add database_cleaner to your *Gemfile`. This lets you say this from the Rails console: DatabaseCleaner.strategy = :truncation DatabaseCleaner.clean You can package this into a nice little Rake task by...

...can e.g. clean the test database by saying on the shell: rake db:clean RAILS_ENV=test If you are using the parallel_tests gem, the task is aware and...

makandra dev
github.com

...example to confirm your output in tests), you can use roo. To easily dump Rails records to XLSX, there is also axlsx_rails (haven't tried it yet). xlsx generation...

If possible, make the autoloaded class static by moving it out of Rails' load path...

...it's usually not part of the Gem's API). Unless you're using Rails 4 (which brings String#indent in ActiveSupport), you'll be best of defining it yourself...

...data in columns. This is helpful for e.g. comparing attributes of a set of Rails records. def tp(objects, *method_names) terminal_width = `tput cols`.to_i cols = objects.count...

...disabled, that all classes are already loaded when browser interaction takes place what makes rails able to find the class even without the namespace...

blog.jayfields.com

...these styles, and system will fail when passing it invalid arguments: system 'bundle exec rails server', '-p 3000' # fails and returns nil This is equivalent to running a command called...

...bundle exec rails" (including spaces in its filename). There is usually no such command anywhere on the $PATH. Note that you should prefer the 2nd approach (list of arguments instead...

...last_synchronized_at: nil, } } ) def validate_analytic_stats_against_json_schema @schema ||= File.read(File.join(Rails.root, 'app', 'models', 'project', "analytic_stats_schema_v#{analytics_stats_version}.json")) analytic_stats_errors = JSON...

...or by setting self.primary_key = "id" in your class definition. Related, but different issue: Rails 2 does not find an association when it is named with a string instead of...

...cassette for the request that fails Copy the request with all parameters Open a rails console, assign the request to a variable and unescape it: my_project> var = "%5B%7B...