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
30
votes
6 answers

Organizing c# project helper or utility classes

What are some best practices for where you should have helper classes in a .NET project? Referring to classes separate from business layer stuff, but presentation and app stuff like appSetting config managers and other code that would sometimes be…
spaghetticowboy
  • 708
  • 1
  • 8
  • 22
30
votes
3 answers

Dynamic Paths in Helper

I'm trying to create a helper method for my admin links. In quite a few views I have the code <% if current_user %> <%= link_to "Edit", edit_model_path(model) %> <%= link_to "New", new_model_path %> <%= link_to "Delete", model, :confirm => "You're a…
Bob
  • 301
  • 1
  • 3
  • 3
29
votes
3 answers

Calling helper method from Rails 3 controller

Is it possible to call helper methods from controller? If yes how to do this in Rails 3?
Achaius
  • 5,904
  • 21
  • 65
  • 122
28
votes
2 answers

Rspec 2 config :type types

In my spec_helper.rb I have config.include Devise::TestHelpers, :type => :controller so that I can actually test my controllers that require the user to be authenticated. However, the spec for the same class in requests needs to sign in as well or…
Aaron
  • 13,349
  • 11
  • 66
  • 105
28
votes
3 answers

Communicate with another app using XPC

I have a windowed app, and to add some functionality I need another app which launches at login and sync data to server if available. I have tried with NSDistributionNotification but its practically useless in a sandboxed app. I looked up XPC and…
user88975
  • 1,618
  • 3
  • 19
  • 29
28
votes
2 answers

Best way to handle view and helper-only constants in Rails

I have a constant that is only used in views, but it's used in different ways in different places. It's an array of option names, and is used for select boxes, but I also use this in other views to see if strings are found in this array, and…
William Jones
  • 18,089
  • 17
  • 63
  • 98
28
votes
6 answers

What is the best way to return multiple tags from a Rails Helper?

I want to create a hidden field and create a link in one helper and then output both to my erb. <%= my_cool_helper "something", form %> Should out put the results of link_to "something", a_path form.hidden_field "something".tableize, :value =>…
Sixty4Bit
  • 12,852
  • 13
  • 48
  • 62
27
votes
5 answers

Rails 3.1: Better way to expose an engine's helper within the client app

I have found a few articles addressing the issue of helpers within an engine not being accessible to the consuming (parent) application. To make sure we are all on the same page, let's say we have this: module MyEngine module ImportantHelper …
ynkr
  • 25,946
  • 4
  • 32
  • 30
25
votes
3 answers

Custom form helpers

Is there a way that I can create a custom form helper so that instead of: special_field_tag :object, :method I can achieve something like: form.special_field :method
user138095
24
votes
3 answers

How do I use UrlHelper from within a Razor helper?

I'm trying to create a Razor helper like this: @helper Render(IEnumerable items) {
    @foreach (var item in items) {
  • Click
  • }
} Only problem here is that…
Mike
  • 7,500
  • 8
  • 44
  • 62
24
votes
4 answers

where to put time format rules in Rails 3?

I am finding myself repeating typing many strftime which I defined. Having watch Ryan Bates's railscasts ep 32/33( I think), I created a custom option for the to_s method as in Time.now.to_s, so that I can do Time.now.to_s(:sw), where :sw is my…
Nik So
  • 16,683
  • 21
  • 74
  • 108
24
votes
2 answers

Handlebars helper - returning HTML not text

I wrote a simple helper for my template. Here's the code: Handlebars.registerHelper('splitQuote', function (string) { if (string.indexOf('|') !== -1) { return string.replace('|', '') + ''; } return string; }); So I…
Adrian
  • 1,499
  • 3
  • 19
  • 26
24
votes
4 answers

Override rails helpers with access to original

I want to use rails' familiar helpers, but with slightly altered functionality. The way I see it, I want to be able to do something like: module AwesomeHelper #... create alias of stylesheet_link_tag to old_stylesheet_link_tag def…
user208769
  • 2,216
  • 1
  • 18
  • 27
23
votes
9 answers

Laravel 5.2 pluck() multiple attributes from Eloquent Model Collection

Laravel 5.2 has pretty nice Helpers, I would like to use them to do following: I have Eloquent Model Collection: $lesson->users(); // returns Eloquent collection of 3 users pluck() function would be useful, but it can get just single parameter.…
Fusion
  • 5,046
  • 5
  • 42
  • 51
23
votes
5 answers

How do you test a Rails controller method exposed as a helper_method?

They don't seem to be accessible from ActionView::TestCase
Teflon Ted
  • 8,696
  • 19
  • 64
  • 78