helpers

Rails 3: @template variable inside controllers is nil

Hi all, i've started using rails 3 beta3 and I have see that the @template variable inside controllers is nil. How I can call helpers methods inside a controller? Thx ...

How can I return javascript from a Ruby on Rails helper method?

I have a Note model, which can contain have either an image link attachment (linktype = "image" or some text (linktype = "text). When I display the notes, the method of display changes depending on the linktype. An example is: <% @notes.each do |q| %> <h2 class="title"><%= q.name %></h2> <% if q.linktype == "other"%> <sc...

Basic View Model class reference question. (ASP.net MVC)

Newbie-ish questions ahead: Where should I put my View Model declarations? I created a file called "ViewModels.cs" in my Models folder. I created a few View Model classes, including one called RatingViewModel: using System; using System.Collections.Generic;var using System.Linq; using System.Web; namespace Web.Model { public class Vi...

Are helpers really faster than partials? What about string building?

I've got a fancy-schmancy "worksheet" style view in a Rails app that is taking way too long to load. (In dev mode, and yes I know there's no caching there, "Completed in 57893ms (View: 54975, DB: 855)") The worksheet is rendered using helper methods, because I couldn't stand maintaining umpteen teeny little partials for the different sor...

how to determine if someone will make a good programmer

My current company is starting a development project with another afiliated company. We are a programming shop but the other company has no developers. We will be creating an app for that company but then the company will take it in charge so they want to have two developers of their own for this, to be involved in all stages of the de...

How do I call a Rails helper method from inside another helper method?

I am writing a helper that needs to call another helper, which generates html. How do I do that? ...

How to write a helper in Ruby on Rails to capture Haml blocks?

I am writing a Rails helper method that will add wrapper html to captured content blocks and replace content_for method, such as - content_for :header do //haml code ..would become - content :header do //haml code In order to do this I am using Haml and Ruby blocks. This is what it looks like def content(name,&block) content_fo...

cakephp accessing view attributes/variables from within a helper

is there a reasonable way to access the view attribute "passedArgs" (or any similar) /* view */ $this->passedArgs from within a Helper? I'd be happy to customize the _construct() of the helper or to customize the app_helper... but I don't want to have to pass $this->passedArgs into the helper on every view or usage. ...

Testing view helpers

I'm currently working on a Rails plugin used for generating iPhone specific HTML meta-tags. I'm trying to use ActionView::TestCase for unit tests but keep getting the same error. See file contents and error below. Any ideas or help would be much appreciated. test_helper.rb require 'rubygems' require 'test/unit' require 'active_support'...

CakePHP - TinyMceHelper helper error: Method TinyMceHelper::__name does not exist

So I'm wanting to implement the TinyMce helper. I've followed instructions from the cakephp bakery but am still getting a error. This is the helpers array in my project controller: var $helpers = array('Form', 'Time', 'Crumb', 'Text', 'Tinymce'); This is the tinymce helper I downloaded: <?php class TinyMceHelper extends AppHelper {...

Can anyone provide a straight forward example to extend the Html.TextBoxFor helper

I'm hoping that someone can provide a simple, straight forward example of extending the Html.TextBoxFor helper. I would like to include a boolean ReadOnly parameter which will (surprise, surprise, surprise) render the control read only if true. I've seen a few examples which didn't quite do the trick and I've tried the following however,...

Custom Helper using the model

Hi, I'm pretty new to MVC and just read an article about helpers. Now I have this code on the View: <div class="display-label">Ingredients: <% foreach (var e in Model.Products_Ingredients) {%> <%: e.Ingredient.Name%><br /> <%: e.Percentage%> <%if (e.Percentage != null) ...

[PHP] Codeigniter request control class

hi all guys, i'm trying to do myself a good simple request control library. this is my code: class CI_Request { public function isAjax() { return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'; } public function isPost() { return isset($_POST)...

where to put time format rules in Rails 3?

Hello, 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 custom method, to retrieve "23 Sep 2010, 5:00PM" for example. But the problem is, I ...

Rails 3: @template variable inside controllers is nil

Hello guys! I have the same problem, as in this question. Did anybody find any solutions for this? So I can't do like this: flash[:notice] = "Successfully created #{@template.link_to('product', @product)}. or like this: @template.title("Page title is here.") It worked perfectly in Rails 2.3. The main idea is to find out, how to u...

Rails Helper that identifies file type of url in link

I'm looking for a helper that changes link_to behaviour if the file is a PDF, i.e. displays a tooltip. How can I write a helper that overrides link_to only if the file is a pdf? ...

Optional parameters for Rails Image Helper

In my current Rails (Rails 2.3.5, Ruby 1.8.7) app, if I would like to be able to define a helper like: def product_image_tag(product, size=nil) html = '' pi = product.product_images.first.filename pi = "products/#{pi}" pa = product.product_images.first.alt_text if pi.nil? || pi.empty? html = image_tag("http...

Change default Rails text_area helper rows/cols

Hello I am finding myself specifying :rows => 5 on all my text_area form helpers, So I looked up its definition and found the DEFAULT_TEXT_AREA_OPTIONS to be the hash dictating these options. However, the hash has this freeze method on it and I looked it up, it means it can't be changed. If you could recommend me some options to try to ...

In Rails, any way to use app/helpers/foo.rb methods in Controller vs in View?

It seems that those helpers in app/helpers/foo.rb can be used in View, but cannot be used in Controller? In some cases, different controllers may need to use the same method but just pass in a different parameter, so in that case, won't it make sense to use a helper in a controller? ...

Rails 3 widget helper partial

Hi! I ran into a big problem in moving my application to Rails 3. I have a view helper which i call 'WidgetHelper'. It helps to render some partials automatically when i refer to it. For example <%= widget('loginbox', :global => true) %> But it not works correctly. It renders HTML code as I want, but escapes the return value, what is...