How to render HTML using a Ruby on Rails API application 5
source link: https://www.codesd.com/item/how-to-render-html-using-a-ruby-on-rails-api-application-5.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to render HTML using a Ruby on Rails API application 5
We're using Ruby on Rails 5.0.0.1 in API-Mode. What Middleware and Configurations do I need to add, in order to being able to render html instead of json in an controller.
Edit:
Thank you all for your answers.
Want I wanted is to render normal erb/haml views. not html in json like 'kartik upadhyay' mentioned. Since the Application is primary an JSON API we didn't want the full blown default Rails Installation, which mean our Application Controller extends from ActionController::API.
My Plan was to make a PdfRendering Controller which includes all Modules needed for ActionView to work. What I rather did was reading the asset pipeline (because we wanted to use sass) and inherit the application controller from ActionController::Base.. as other rails apps would do.
It's not the nicest solution since you're including the whole ActionController::Base and all of it's Feature that you may not be using. But it's still slimmer that a full Blown Rails installation (especially the middleware aka. sessions etc.)
Put inside your action:
respond_to do |format|
format.html
format.xml
format.json
end
http://guides.rubyonrails.org/action_controller_overview.html is a nice start. And maybe it's nice to reconsider use "API mode" if you're returning html.
best!
Recommend
-
13
Introduction In this tutorial, you will learn how to dockerize a Ruby on Rails application. The application we’re going to build will make use of PostgreSQL, Redis, and Sidekiq. We’ll also be using Uni...
-
10
Setting Up AppSignal Monitoring for a Ruby on Rails Application Milica Maksimović, Stefan Verkerk on Dec 10, 2020 “I absolutely love AppSignal.”
-
13
Ruby Magic How to Use Mixins and Modules in Your Ruby on Rails Application Cleiviane Costa on Jan 13, 2021 “I absolutely love AppSignal.”
-
4
Using Webpacker in Your Ruby on Rails Application — a Deep Dive Paweł Dąbrowski on Feb 17, 2021 “I absolutely love AppSignal.” Discover...
-
4
Published on 7 June 2021 in ruby-on-rails Select email provider at runtime in a Ruby on Rails application Recently we had a requirement wher...
-
8
Application Favicon in Ruby on Rails advertisements This question already has an answer here: Adding icon to rails applicati...
-
1
How To Develop Web Application Using Ruby on Rails Want t...
-
7
Ruby on Rails Application Monitoring with AppSignalUnathi Chonco on Dec 1, 2021
-
6
Next Level Ruby on Rails Application Monitoring with AppSignal
-
6
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK