Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to render layout from a database in rails 4?

Is it possible to read a string from a text data field and render it as a layout?

If I use this, it looks for a file 1.html.erb under layouts:

layout: '1'
like image 648
markhorrocks Avatar asked Oct 03 '13 11:10

markhorrocks


People also ask

How do I render in Ruby on Rails?

From the controller's point of view, there are three ways to create an HTTP response: Call render to create a full response to send back to the browser. Call redirect_to to send an HTTP redirect status code to the browser. Call head to create a response consisting solely of HTTP headers to send back to the browser.

How can you tell Rails to render without a layout *?

By default, if you use the :text option, the text is rendered without using the current layout. If you want Rails to put the text into the current layout, you need to add the layout: true option.

What is the difference between a Rails layout and a Rails template '? What is each used for?

From http://www.tutorialspoint.com/ruby-on-rails/rails-layouts.htm : A layout defines the surroundings of an HTML page. It's the place to define common look and feel of your final output. Layout files reside in app/views/layouts. Template is a general term for the view files.

How should you use nested layouts in Rails?

Rails provides us great functionality for managing layouts in a web application. The layouts removes code duplication in view layer. You are able to slice all your application pages to blocks such as header, footer, sidebar, body and etc.


1 Answers

You can pass the name of a layout in the call to render

def show
  @team = Team.find_by name: 'Red Sox'
  render action: :show, layout: @team.preferred_layout
end
like image 59
AndyV Avatar answered Oct 20 '22 19:10

AndyV