...following helper. def greeting message = ''.html_safe message << 'Welcome to ' message << content_tag(:span, Rails.env, class: 'greeting--location') content_tag :div, message, class: 'greeting' end That looks clumsy and is...

...say something like this? def greeting render_haml <<-HAML .greeting Welcome to %span.greeting--location = Rails.env HAML end It would be, and you can have it, too. You simply need to...

...part is a bit lengthy, but it allows you to debug strange bugs with Rails autoloading the wrong constants. Due to the constant lookup rules above, Rails sometimes guesses wrong...

...in development and production, but the problem exist for both environment. Development During development, Rails unloads all classes after every request. This way code changes take effect immediately, without requiring...

...like to split a Ruby array into pairs of two, you can use the Rails ActiveSupport method in_groups_of: >> [1, 2, 3, 4].in_groups_of...

...split a Ruby array into a given number of groups, you can use the Rails ActiveSupport method in_groups: >> [1, 2, 3, 4, 5, 6].in_groups...

There are different ways to run rake: On Rails 4.1+ projects, you have Spring and its binstubs which dramatically improve boot-up time for Rake and similar. You need to...

rake is a function rake () ... Next, try running rake routes on a Rails 4.1+ project -- the 2nd time should be significantly faster. On older projects you should always...

...the need to enter user and password, you can say the following in any Rails 2 project: script/dbconsole -p In Rails 3 you can say: rails dbconsole -p

Provide a stable API for working with scopes across multiple versions of Rails, since Rails has a tradition of breaking details of its scope API every other release...

DETAIL: There is 1 other session using the database. This could be the rails server, rubymine and many more. Beside terminating the session connection manually you can also find...

...out the pid and kill the process. 1. rails db 2. SELECT * FROM pg_stat_activity; datid | 98359 datname | foo_development pid | 21633 usesysid | 16384 usename | username application_name | DataGrip...

makandra dev

...and The...

...field should have the error...

...steps now have built-in support for Rails and Bootstrap (v3-v5) error classes. When using Bootstrap, it is no longer necessary to...

...behaves like an unordered Hash, but is much faster. Info If you're using Rails you already have concurrent-ruby in your bundle. hamster hamster provides several collection classes, such...

makandra dev

There is a practical short list for valid/invalid example email addresses - Thanks to Florian L.! The definition for valid emails...

I got this error when running Rails 2.3 tests for Rails LTS. More stacktrace: NoMethodError: undefined method `cache' for Gem:Module /vagrant/rails-2-3-lts-repository/railties/lib/rails_generator/lookup.rb:212:in `each' /vagrant/rails-2-3-lts-repository/railties/lib/rails_generator/lookup.rb:146:in `to_a...

stackoverflow.com

...scenario, the code below lets you write this: Given my IP address is 188.174.117.205 Rails 3 Given /^my IP address is "(.*?)"$/ do |ip| ActionDispatch::Request.any_instance.stub(:remote_ip).and_return(ip...

Rails 2 You will need the following step definitions: Given /^my IP address is (\d+\.\d+\.\d+\.\d+)$/ do |ip| ApplicationController.stubbed_request_ip = ip end After do ApplicationController.stubbed_request...

...up 20160517112656 Migrate pages to page versions up 20160518112023 ********** NO FILE ********** When you tell Rails to roll back, it tries to roll back the latest change that was migrated. In...

...have the corresponding migration file for. Hence, it can not be rolled back and Rails aborts silently. This happens for example when you migrated on the master branch at some...

stackoverflow.com

Before Rails 3.2.14, when supplying an invalid locale to I18n, it would fall back to its config.i18n.default_locale (which is :en by default). Eventually, this will be changed to raise...

...an error by default -- for now, it shows a deprecation warning. Since Rails 3.2.14 and 3.2.15 did not include security updates, you might not have applied them and probably now...

...to append filepaths to it. With this method, Ruby code can look like this: Rails.root/"features"/"fixtures"/"picture.jpg" Alternatively you can use the #join method, which feels less magic: Rails.root.join...

We upgraded a Rails 2 application to Rails 3.2 and Ruby 2.1, changed the mysql adapter from mysql to mysql2, but did not activitate the asset pipeline. Instead we used...

...ruby with something like user_ids = ActiveRecord::Base.connection.select_values(Message.select(:user_id).to_sql) # Rails 2 user_ids = Message.all.pluck(:user_id) # Rails 3+ User.where(:id => user_ids).update_all(:has...

I believe that when WEBrick has trouble bringing up your Rails application, the WEBrick component that is supposed to print you a pretty error message has a bug and sometimes...

...pointed to the actual problem. Possible causes discovered by looking at the logs A Rails plugin would require the sqlite3 gem, but that gem wasn't in the Gem bundle...

...which requires ApplicationController when loaded. When your ApplicationController requires later-loaded gems when loaded, Rails will not boot. Here is an example for an ApplicationController requiring Aegis::Controller from the...

...In this case aegis must be listed before resource_controller in your Gemfile or Rails will not boot...

...all will run all RSpec examples and Cucumber features. The report will be written RAILS_ROOT/coverage/index.html. Here is what the task does in detail: Generates aggregated coverage of both RSpec...

Works with Rails 2 and Rails 3 Reports for app/**/*.rb and nothing else If called with an environment variable IGNORE_SHARED_TRAITS=true it ignores Modularity traits...

...you need to make a static web page and find yourself missing all your Rails comforts, take a look at StaticMatic. This works like an extremely stripped down version of...

...Rails, giving you HAML SASS helpers partials When done, everything is simply compiled to static HTML and CSS, so no need to install anything on your server. If you receive...

Note: In Rails 3+ you can use Array.wrap instead of the solution here. In the past you could use Array(...) or #to_a to turn an object into an array...

...you can copy the attached file to config/initializers or require it from a non-Rails project. You can now say: 5.listify # => [5] [5].listify # => [5] Note that this method no...

RSpec 1 (Rails 2) With the most recent spec_candy.rb helpers you can say: User.stub_any_instance(:foo => :bar) user = User.new user.foo # => :bar RSpec 2 (Rails 3) RSpec 2 comes with...

...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...