Questions tagged [actionview]

For questions about Action Views, HTML and Ruby templates used in Ruby on Rails

HTML and Ruby templates used in .

Action View is the View part of for , and is a part of the Ruby-On-Rails Action Pack.

474 questions
119
votes
11 answers

How do I render a partial of a different format in Rails?

I'm trying to generate a JSON response that includes some HTML. Thus, I have /app/views/foo/bar.json.erb: { someKey: 'some value', someHTML: "<%= h render(:partial => '/foo/baz') -%>" } I want it to render /app/views/foo/_baz.html.erb, but it…
James A. Rosen
  • 60,042
  • 58
  • 173
  • 260
67
votes
4 answers

Rails: Should partials be aware of instance variables?

Ryan Bates' nifty_scaffolding, for example, does this edit.html.erb <%= render :partial => 'form' %> new.html.erb <%= render :partial => 'form' %> _form.html.erb <%= form_for @some_object_defined_in_action %> That hidden state makes me feel…
Alexandre
  • 4,687
  • 7
  • 27
  • 35
57
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,027
  • 3
  • 25
  • 29
56
votes
3 answers

How do I extract Rails view helpers into a gem?

I have a set of rails view helpers that I use regularly, and would like to package them up into a gem, such that I could just put a line in my Gemfile, and have the helpers accessible from my views. I have created gems before using Bundler, and…
noli
  • 15,285
  • 7
  • 41
  • 59
39
votes
3 answers

What should I pass for root when inflating a layout to use for a MenuItem's ActionView?

I have an ImageView that I attach to a MenuItem as its ActionView (the item appears in the ActionBar). The layout for this view comes from XML. I'm inflating it like so: ImageView actionView = (ImageView) layoutInflater.inflate( …
dlf
  • 8,245
  • 3
  • 31
  • 51
38
votes
4 answers

Dynamic error pages in Rails 3

In Rails 2.3.x, you can override render_optional_error_file like so: # ApplicationController.rb protected def render_optional_error_file(status_code) render :template => "errors/500", :status => 500, :layout => 'application' end However,…
38
votes
3 answers

Rails passing form_for object to partial

I would like to pass the form_for object to a partial: <%= form_for @price do |f| %> ... <%= render :partial => "price_page", :object => @price, :as => :f %> ... <% end %> When I call: f.radio_button Brings the error: undefined method…
Harry
  • 1,569
  • 4
  • 17
  • 33
25
votes
8 answers

How can I use strip_tags in regular Ruby code (non-rails)?

I need to turn HTML into plain text. There's a nice function that does that in ActionView's SanitizeHelper, but I have trouble understanding how I can reference it and use it in a simple test.rb…
sanitizeme
  • 251
  • 1
  • 3
  • 3
24
votes
3 answers

Custom Action View can't be clicked

I am trying to add a custom ActionView to my ActionBar. I am trying to add the common refresh button. (ImageButton, ProgressBar inside a FrameLayout) but if I use an ActionView onOptionsItemSelected() is never called. Here's the code: In my…
Macarse
  • 87,001
  • 42
  • 169
  • 229
22
votes
3 answers

ActionView::Template::Error (960.css isn't precompiled)

I have an iframe which renders a partial and is not part of the main application layout or asset pipeline. I'd like to include some style sheets, however I am getting this error: ActionView::Template::Error (960sm.css isn't precompiled): Rails…
hagope
  • 5,123
  • 6
  • 32
  • 49
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 #…
18
votes
1 answer

Specifying format: "xml" ignored with render_to_string

I have an action that needs to render a view to string. The view is called index.xml.erb. I am trying to achieve this with render_to_string: my_string = render_to_string(layout: false, format: "xml") render_to_string is instead rendering the…
YWCA Hello
  • 2,857
  • 4
  • 26
  • 39
18
votes
4 answers

How do I expire a view cached fragment from console?

Something like Rails.cache.delete('site_search_form') doesn't seem to work. Is this possible? Thanks.
Ben Crouse
  • 8,110
  • 5
  • 32
  • 50
18
votes
3 answers

rails - how to render a JSON object in a view

right now I'm creating an array and using: render :json => @comments This would be fine for a simple JSON object, but right now my JSON object requires several helpers which is breaking everything and requiring helper includes in the controller…
AnApprentice
  • 97,752
  • 174
  • 583
  • 971
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
1
2 3
31 32