Questions tagged [helper]

Additional functionality not defined in a class that the helper operates on.

A helper is a method commonly used in object-oriented programming to provide additional functionality to classes that not directly associated with the class. This is known as an Inversion of Responsibility.

Helper methods are typically grouped into a single helper class through the delegation pattern.

2672 questions
223
votes
2 answers

What do helper and helper_method do?

helper_method is straightforward: it makes some or all of the controller's methods available to the view. What is helper? Is it the other way around, i.e., it imports helper methods into a file or a module? (Maybe the name helper and helper_method…
nonopolarity
  • 146,324
  • 131
  • 460
  • 740
91
votes
4 answers

Why are all Rails helpers available to all views, all the time? Is there a way to disable this?

Why can I access helper methods for one controller in the views for a different controller? Is there a way to disable this without hacking/patching Rails?
Nate Smith
  • 1,103
  • 1
  • 15
  • 19
88
votes
4 answers

Rails- nested content_tag

I'm trying to nest content tags into a custom helper, to create something like this:
Note that the input is not…
christo16
  • 4,843
  • 5
  • 42
  • 53
88
votes
6 answers

conditional on last item in array using handlebars.js template

I am leveraging handlebars.js for my templating engine and am looking to make a conditional segment display only if it is the last item in array contained in the templates configuration object. { columns:…
techie.brandon
  • 1,638
  • 2
  • 18
  • 27
81
votes
5 answers

How to access URL helper from rails module

I have a module with a function. It resides in /lib/contact.rb: module Contact class << self def run(current_user) ... end end end I want to access the URL helpers like 'users_path' inside the module. How do I do that?
sizzle
  • 2,222
  • 2
  • 21
  • 32
67
votes
10 answers

Rails 3. How to add a helper that ActiveAdmin will use?

I'm creating a helper to be used by Formtastic but I get the undefined local variable or method error. I don't know where to put it so it can work. I already tried in the application_helper.rb and in app/helpers/active_admin/view_helpers.rb
leonel
  • 10,106
  • 21
  • 85
  • 129
59
votes
4 answers

How to mixin and call link_to from controller in Rails?

This seems like a noob question, but the simple answer is eluding me. I need to call link_to in an ActionController method to spit out an HTML link. ActionView::Helpers::UrlHelper.link_to calls url_for, but this calls the AV module's version…
tribalvibes
  • 2,097
  • 3
  • 25
  • 30
53
votes
2 answers

How do I use helpers in rake?

Can I use helper methods in rake?
Sam Kong
  • 5,472
  • 8
  • 51
  • 87
52
votes
2 answers

How to add class to an image_tag rails helper

I have the following code: <%= image_tag iterator.image.url(:small), :class => "img_preview" %> But the rendered HTML shows: Clean_wave Why the "class" attribute isn't…
content01
  • 3,115
  • 6
  • 41
  • 61
52
votes
2 answers

Is it possible to nest helpers inside the options hash with handlebars?

For instance, is there a way to nest my "i18n" helper inside another helper's hash variable? {{view "SearchView" placeholder="{{t 'search.root'}}" ref="search" url="/pages/search" className='home-search' polyfill=true}}
mateusmaso
  • 7,843
  • 6
  • 41
  • 54
50
votes
8 answers

Rails: Preserving GET query string parameters in link_to

I have a typical search facility in my app which returns a list of results that can be paginated, sorted, viewed with a different records_per_page value, etc. Each of these options is controlled by parameters in the query string. A simplified…
Vincent
  • 16,086
  • 18
  • 67
  • 73
49
votes
5 answers

How do I make global helper functions in laravel 5?

If I wanted to make a currentUser() function for some oauth stuff I am doing where I can use it in a view or in a controller (think rails, where you do helper_method: current_user in the application controller). Everything I read states to create a…
TheWebs
  • 12,470
  • 30
  • 107
  • 211
49
votes
1 answer

How to deal with Mac OS X Helper/Main app architecture regarding core data, shared preferences and notifications?

I'm having some architectural doubts about a project (Mac OS X app) I'm working on. It basically consists of two elements: a daemon that runs in the background gathering some data and a viewer used to represent the gathered data. The daemon should…
Niels Mouthaan
  • 1,010
  • 8
  • 19
48
votes
2 answers

How to test ApplicationController method defined also as a helper method?

In my ApplicationController I have a method defined as a helper method: helper_method :some_method_here How do I test ApplicationController in RSpec at all? How do I include/call this helper method when testing my views/helpers? I'm using Rails3…
Mirko
  • 5,207
  • 2
  • 37
  • 33
47
votes
6 answers

Is the word "Helper" in a class name a code smell?

We seems to be abstracting a lot of logic way from web pages and creating "helper" classes. Sadly, these classes are all sounding the same, e.g ADHelper, (Active Directory) AuthenicationHelper, SharePointHelper Do other people have a large number of…
Kye
  • 5,919
  • 10
  • 49
  • 84
1
2 3
99 100