我有一个像这样的控制器:
def show
@professor = Professor.find(params[:id])
respond_to do |format|
format.html
format.pdf do
render :pdf => "file_name"
end
end
end
Run Code Online (Sandbox Code Playgroud)
这样一个简单的视图:
<p>Professor: <%= @professor.first_name %></p>
<p>Email: <%= @professor.email if @professor.email %></p>
Run Code Online (Sandbox Code Playgroud)
我还有一个'application.html.erb'布局;
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%= content_for?(:title) ? yield(:title) : "Myapp" %></title>
<meta name="description" content="">
<meta name="author" content="">
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
<%= yield(:head) %>
</head>
<body>
<header class="navbar navbar-fixed-top">
<nav …Run Code Online (Sandbox Code Playgroud)