Questions tagged [actionviewhelper]

For questions about helper classes for the Ruby on Rails module Action View.

For questions about helper classes for the module .

86 questions
29
votes
3 answers

Using helpers in rails 3 to output html

I'm trying my best to build a helper that outputs a <'ul> consisting of all the members of a collection. For each member of the collection I want to print out a <'li> that has a title, and a div of links to CRUD the member. This is pretty similar…
TheDelChop
  • 7,938
  • 4
  • 48
  • 70
23
votes
2 answers

How do I use an ActionView::Helper in a Ruby script, outside of Rails?

I am looking to use ActionView::Helpers::NumberHelper from a Ruby script. What all do I need to require etc.?
Pete
  • 233
  • 2
  • 4
22
votes
1 answer

How can I add a view path to Rails's partial rendering lookup?

I'd like to have the following directory structure: views/ app1/ users/_user.html.erb users/index.html.erb app2/ users/index.html.erb shared/ users/_user.html.erb users/index.html.erb In my view, I'd call #…
17
votes
4 answers

How to call 'time_ago_in_words' from a FunctionalTest?

I'm using 'time_ago_in_words' function in a view, and I need to test the output in the FunctionalTest. But the test can not see 'time_ago_in_words' helper function. What should I do in order to use these helper methods from FunctionalTests?
Raiden
  • 173
  • 1
  • 6
15
votes
4 answers

Rails 4: collection_select not inserting 'class' attribute?

What am I missing here? I am working with Rails 4.0.0 and trying out the new Bootstrap 3.0.0rc1. I have a simple 'recipe box' app that has a Recipe model and a Category model that feeds a 'category' field on the Recipe. In the recipes#new view, I…
user2670683
  • 243
  • 1
  • 3
  • 7
13
votes
1 answer

Rails problem with humanize

I am trying to humanize the symbols that are the keys for a hash c.each_key{ |f| humanize(f.to_s)} but for some reason, i get an error like so ActionView::Template::Error (undefined method 'humanize' for #<#:0xb5b6598>) any idea…
Amit
  • 3,952
  • 7
  • 46
  • 80
12
votes
2 answers

Rails console - use image_tag method

How can I execute a image_tag method in a Rails console Run the console $ rails c Load helpers include ActionView::Helpers Execute the command image_tag('test.png') I got a strange error. Please help!
xpepermint
  • 35,055
  • 30
  • 109
  • 163
12
votes
2 answers

How to include ActionView helpers in the assets pipeline?

How to include Rails view helpers to be accesible by assets pipeline execution context? An example use case would be to generate the markup for a form, using form_tag helper method, and make it available to a Javascript template (like handlebars,…
brutuscat
  • 3,139
  • 2
  • 28
  • 33
11
votes
1 answer

Rails form_tag form writing - with non-active record model

I'm somewhat of a Rails newbie. I'm writing a couchrest-rails app, so am not using activerecord for this model. I just figured out that that means that form_for(@model) won't work. I'm trying to work out how to use form_tag -- but most of the…
Pauli Price
  • 4,187
  • 3
  • 34
  • 62
10
votes
5 answers

How to access a Rails controller view context from outside of a controller?

I am working on cleaning up some code that relies on some custom controller helper methods, by creating a "plain old Ruby" presenter object. In my controller, I am able to pass the view context to the class: def show # old code:…
Andrew
  • 227,796
  • 193
  • 515
  • 708
9
votes
4 answers

Rails - Date time select in specified time zone

I'm working with an app for a concert tour website, where all times (announcement times, on-sale start times, and event start times) are local to each particular venue's time zone. I take the user entered date/time where applicable and run a…
8
votes
5 answers

How can I stop the password field being pre-populated on edit?

I have this problem all the time in my rails apps and I still need the correct solution. Whenever a user edits their own record the password field is being populated. I suspect its Firefox as setting @user.password = nil in the edit action doesn't…
tsdbrown
  • 5,038
  • 3
  • 36
  • 40
8
votes
2 answers

RubyOnRails: How do I use helper methods in Rails Console?

Probably something wrong with my setup: irb(main):001:0> truncate("Once upon a time in a world far far away", :length => 17) NoMethodError: undefined method `truncate' for main:Object from (irb):1 from…
TopperH
  • 2,183
  • 18
  • 33
6
votes
4 answers

Accessing URL Helpers when Rendering Partials from Rails Models

I have to render some templates and send the HTML block to SendGrid for email substitution. So, unfortunately, I am doing some rendering in model like this: view = ActionView::Base.new(Rails.configuration.paths["app/views"].first) …
6
votes
5 answers

Rails: Preselect a value in ActionView-Helper 'collection_select'

I'm trying to get the ActionView-Helper collection_select to take a value that will be preselected in the dropdown-menu. Neither (:selected in the html-option-hash) <%= collection_select(:my_object, :my_method, @my_collection, :id,…
Javier
  • 2,491
  • 4
  • 36
  • 57
1
2 3 4 5 6