Dynamic Paths in Helper

basically you need to transform the class name of the model into something pointing to the correct path. model_name = m.class.to_s.underscore And then use it to call the appropriate path methods link_to “edit”, send(“edit_#{model_name}_path”, m) As an aside, you don’t need to put the link_tos in #{} because that function simply returns a string.

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

How can I use the rails helper “distance_of_time_in_words” in plain old ruby (non-rails)

This should work: require ‘action_view’ include ActionView::Helpers::DateHelper Both of these need to be done for a couple of reasons. First, you need to require the library, so that its modules and methods are available to be called. This is why you need to do require ‘action_view’. Second, since distance_of_time_in_words is module, which does not stand … Read more

What are good uses for class helpers?

I’m using them: To insert enumerators into VCL classes that don’t implement them. To enhance VCL classes. To add methods to the TStrings class so I can use the same methods in my derived lists and in TStringList. TGpStringListHelper = class helper for TStringList public function Last: string; function Contains(const s: string): boolean; function FetchObject(const … Read more