Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
class HelloWorldController < AbstractController::Base
include AbstractController::Rendering
include AbstractController::Layouts
include AbstractController::Helpers
include AbstractController::Translation
include AbstractController::AssetPaths
include ActionController::UrlWriter
# Uncomment if you want to use helpers defined in ApplicationHelper in your views
# helper ApplicationHelper
# Make sure your controller can find views
self.view_paths = "app/views"
# You can define custom helper methods to be used in views here
# helper_method :current_admin
# def current_admin; nil; end
def show
render template: "hello_world/show"
# or, for partials:
# render partial: "hello_world/show"
end
end
<h1>Hello, World!</h1>
# From your model, observer or library, call:
HelloWorldController.new.show
# => "<h1>Hello, World!</h1>\n"
@rdetert

This comment has been minimized.

Show comment Hide comment
@rdetert

rdetert Feb 25, 2011

This doesn't seem to work for partials.

rdetert commented Feb 25, 2011

This doesn't seem to work for partials.

@hubertlepicki

This comment has been minimized.

Show comment Hide comment
@hubertlepicki

hubertlepicki Feb 25, 2011

I have updated the gist. Looks like you have to call render method now -- both versions (template and partial) work for me on 3.0.4

Owner

hubertlepicki commented Feb 25, 2011

I have updated the gist. Looks like you have to call render method now -- both versions (template and partial) work for me on 3.0.4

@hubertlepicki

This comment has been minimized.

Show comment Hide comment
@hubertlepicki

hubertlepicki Feb 25, 2011

please let me know if it doesn't work...

Owner

hubertlepicki commented Feb 25, 2011

please let me know if it doesn't work...

@rdetert

This comment has been minimized.

Show comment Hide comment
@rdetert

rdetert Feb 25, 2011

I had to call it the old fashioned way by going 'render :partial => "hello_world/show"'

Another GOTCHA is you'll need to set this: self.assets_dir = '/app/public' if you want to use something like image_tag in your views

rdetert commented Feb 25, 2011

I had to call it the old fashioned way by going 'render :partial => "hello_world/show"'

Another GOTCHA is you'll need to set this: self.assets_dir = '/app/public' if you want to use something like image_tag in your views

@hubertlepicki

This comment has been minimized.

Show comment Hide comment
@hubertlepicki

hubertlepicki Feb 25, 2011

yes, pretty sure both are expected behaviors

Owner

hubertlepicki commented Feb 25, 2011

yes, pretty sure both are expected behaviors

@guipdutra

This comment has been minimized.

Show comment Hide comment
@guipdutra

guipdutra Aug 12, 2013

I want to render with the assets, I have to do anything else?

I want to render with the assets, I have to do anything else?

@bradrobertson

This comment has been minimized.

Show comment Hide comment
@bradrobertson

bradrobertson Jan 15, 2014

any idea how to get this to work on Rails 3.2, specifically with proper digested asset urls? The above code doesn't work with rails 3.2

any idea how to get this to work on Rails 3.2, specifically with proper digested asset urls? The above code doesn't work with rails 3.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment