Questions tagged [helper]
Additional functionality not defined in a class that the helper operates on.
2,683
questions
225
votes
2
answers
110k
views
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 ...
92
votes
4
answers
39k
views
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?
89
votes
6
answers
83k
views
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.
{
...
88
votes
4
answers
56k
views
Rails- nested content_tag
I'm trying to nest content tags into a custom helper, to create something like this:
<div class="field">
<label>A Label</label>
<input class="medium new_value" size="20" ...
84
votes
5
answers
58k
views
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 '...
69
votes
10
answers
33k
views
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 ...
59
votes
4
answers
24k
views
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 ...
53
votes
2
answers
92k
views
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:
<img src="/actives/hotels/13/small/clean_wave.jpg?1317675452"...
53
votes
2
answers
42k
views
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-...
53
votes
2
answers
23k
views
How do I use helpers in rake?
Can I use helper methods in rake?
50
votes
8
answers
31k
views
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 ...
49
votes
5
answers
50k
views
How do I make global helper functions in laravel 5? [duplicate]
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 ...
49
votes
6
answers
17k
views
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,
...
49
votes
1
answer
1k
views
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 ...
48
votes
2
answers
35k
views
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 ...
47
votes
7
answers
21k
views
(PartialView) The model item passed into the dictionary is of type 'Customer', but this dictionary requires a model item of type 'UserProfile'
@model Customer
@Html.Partial("_UserProfile", (UserProfile)Model.UserProfile)
When i run this code, i get this error:
The model item passed into the dictionary is of type 'Customer', but this ...
47
votes
5
answers
27k
views
How do I test helpers in Rails?
I'm trying to build some unit tests for testing my Rails helpers, but I can never remember how to access them. Annoying. Suggestions?
46
votes
6
answers
7k
views
When to use Helpers instead of Partials
In a rails application, in which situation would you use a partial and when would you use a helper? I find both very similar, since they represent markup fragments.
Is there a convention around this? ...
45
votes
12
answers
84k
views
"undefined method" when calling helper method from controller in Rails
Does anyone know why I get
undefined method `my_method' for #<MyController:0x1043a7410>
when I call my_method("string") from within my ApplicationController subclass? My controller looks like
...
43
votes
1
answer
4k
views
Silex & Twig helpers in custom error pages
I'm struggling with a problem while rendering a custom error page in Silex.
According to what I found in this link: http://refactoring.us/silex/custom-error-pages-with-silex-and-twig/.
I am trying to ...
41
votes
6
answers
10k
views
Rails article helper - "a" or "an"
Does anyone know of a Rails Helper which can automatically prepend the appropriate article to a given string? For instance, if I pass in "apple" to the function it would turn out "an apple", whereas ...
37
votes
14
answers
42k
views
Shorten long numbers to K/M/B?
I've googled this a lot but i can't find any helpful functions based on my queries.
What i want is:
100 -> 100
1000 -> 1,000
142840 -> 142,840
BUT
2023150 -> 2.023M ( i still want 3 ...
37
votes
10
answers
17k
views
What are good uses for class helpers?
Delphi (and probably a lot of other languages) has class helpers. These provide a way to add extra methods to an existing class. Without making a subclass.
So, what are good uses for class helpers?
37
votes
2
answers
19k
views
Rails - How to add a format to an url helper?
how can I make an URL helper create an URL in a given request/response format?
For example, in my test I have the following:
get(activity_url(activity))
This will returns me an HTML on the @...
36
votes
3
answers
19k
views
Local variables before return statements, does it matter?
Sorry if this is a newbie question but I couldn't find an answer for this.
Is it better to do this:
int result = number/number2;
return result;
or:
return number/number2;
I know integers use ...
34
votes
1
answer
17k
views
How can I use the rails helper "distance_of_time_in_words" in plain old ruby (non-rails)
Rails has an helper which converts distance of time in words using distance_of_time_in_words
What do I need to include if I am just using ruby at the irb prompt to get this function?
I tried require ...
33
votes
17
answers
14k
views
Strange error in rails - missing helper
I am not sure , but this might be associated with a crashed computer. After restarting (after the crash) I get a missing helper error where the helper name is wrong. Switching branches has no effect ...
33
votes
3
answers
20k
views
Using sanitize within a Rails controller
I'm trying to call sanitize within a controller. Here's what I tried:
class FooController < ApplicationController
include ActionView::Helpers::SanitizeHelper
# ...
end
However, I'm getting ...
33
votes
6
answers
36k
views
Lightweight JDBC helper library alternative to Apache Commons DbUtils [closed]
I've just developed my own tiny little JDBC helper library, and I've already realized what a maintenance nightmare it will be.
I'm not looking for a full fledged ORM, like Hibernate, just something ...
32
votes
5
answers
21k
views
Loop & output content_tags within content_tag in helper
I'm trying a helper method that will output a list of items, to be called like so:
foo_list( ['item_one', link_to( 'item_two', '#' ) ... ] )
I have written the helper like so after reading Using ...
30
votes
3
answers
18k
views
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", ...
30
votes
6
answers
34k
views
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 ...
29
votes
3
answers
20k
views
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?
29
votes
6
answers
8k
views
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", ...
28
votes
2
answers
13k
views
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 ...
28
votes
3
answers
19k
views
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 ...
28
votes
2
answers
14k
views
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 ...
27
votes
5
answers
10k
views
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 ...
25
votes
3
answers
14k
views
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
25
votes
4
answers
12k
views
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 ...
24
votes
2
answers
23k
views
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('|', '<...
24
votes
4
answers
11k
views
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 ...
24
votes
3
answers
39k
views
E_ACCESSDENIED when creating a host-only interface on virtualbox via vagrant [closed]
When attempting to run vagrant up after upgrading to VirtualBox 6.1.28, the following error message is received
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling ...
24
votes
3
answers
20k
views
How do I use UrlHelper from within a Razor helper?
I'm trying to create a Razor helper like this:
@helper Render(IEnumerable<MyItem> items) {
<ul>
@foreach (var item in items) {
<li><a href="@Url.Content(item.Url)">...
23
votes
9
answers
50k
views
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 ...
23
votes
5
answers
15k
views
How do you test a Rails controller method exposed as a helper_method?
They don't seem to be accessible from ActionView::TestCase
23
votes
5
answers
37k
views
System.Web.Helpers not found in VS2015
I'm trying to add some JSON parsing to the C# code in VS2015 but I can't find:
System.Web.Helpers
as the MS documentation suggests. I've looked at other people's questions of a similar nature (almost ...
22
votes
3
answers
40k
views
Wildfly 9 http to https
I want to redirect the request from HTTP to HTTPS. I am using wildfly 9. After a google search I found the following, but it is not working.
I hope somebody
<subsystem xmlns="urn:jboss:domain:...
22
votes
5
answers
43k
views
Extension Method vs. Helper Class [duplicate]
Possible Duplicate:
Extension Methods vs Static Utility Class
I am building an API of general functions which perform actions based upon objects in .NET. For example; I have created a function ...
21
votes
2
answers
13k
views
Check if Model is valid outside of Controller
I have a helper class that is passed an array of values that is then passed to a new class from my Model. How do I verify that all the values given to this class are valid? In other words, how do I ...