actionview

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

大憨熊 提交于 2019-11-26 21:46:27
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 will only render /app/views/foo/_baz.json.erb . Passing :format => 'html' doesn't help. Tim Haines Beginning with Rails 3.2.3, when calling render :partial (only works outside of the respond_to block). :formats => [:html] instead of :format => 'html' Sam Stokes What's wrong with render :partial => '/foo/baz.html.erb' ? I just tried this to render an

Dynamic error pages in Rails 3

此生再无相见时 提交于 2019-11-26 15:20:42
问题 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, Rails 3 no longer has render_optional_error_file . Instead, you need to override rescue_action_in_public , which you can do like so: # config/initializers/error_page.rb module ActionDispatch class ShowExceptions protected def rescue_action_in_public(exception

How do I extract Rails view helpers into a gem?

允我心安 提交于 2019-11-26 15:13:22
问题 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 Jeweler, however, I'm not all all clear on how to organize the Rails view helpers in a gem, and include them into rails. I would appreciate any pointers, or links to up-to-date tutorials on how to do this for Rails 3 Thanks Just to clarify: The

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

前提是你 提交于 2019-11-26 09:07:01
问题 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 will only render /app/views/foo/_baz.json.erb . Passing :format => \'html\' doesn\'t help. 回答1: Beginning with Rails 3.2.3, when calling render :partial (only works outside of the respond_to block). :formats => [:html] instead of :format =>