Strange error in rails – missing helper

The problem seems to have been introduced in the latest version of ruby, ruby 2.2.0. Try this experiment: in rails console/or irb: [1] pry(main)>File.expand_path (“./”) => “/users/xxxx/Sites/xxxx” and in the terminal window: ]$ pwd /users/xxxx/sites/xxxx See the different case? If you get that, then deep in the bowels of active support a regex goes south. … Read more

Shorten long numbers to K/M/B?

Use number_format(): if ($n < 1000000) { // Anything less than a million $n_format = number_format($n); } else if ($n < 1000000000) { // Anything less than a billion $n_format = number_format($n / 1000000, 3) . ‘M’; } else { // At least a billion $n_format = number_format($n / 1000000000, 3) . ‘B’; } I … Read more

What do helper and helper_method do?

The method helper_method is to explicitly share some methods defined in the controller to make them available for the view. This is used for any method that you need to access from both controllers and helpers/views (standard helper methods are not available in controllers). e.g. common use case: #application_controller.rb def current_user @current_user ||= User.find_by_id!(session[:user_id]) end … Read more