当我使用 wicked_pdf gem 时,它会重定向到查看页面而不是下载选项
When i used wicked_pdf gem it is redirecting to a view page instead of download option
我想在rails中实现文件导出为pdf。但不是下载选项而是重定向到视图页面 http://localhost:3000/xmls?pdf=xml.pdf&template=xmls_controller%2Findex.html.erb
我使用了 render 但抛出错误,这就是我使用 redirect_to
的原因
Template is missing
Missing template xmls_controller/index.html.erb with {:locale=>[:en], :formats=>[:pdf], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :arb, :jbuilder]}. Searched in: * "/home/god/Documents/xml_parsing/xml_parsing/app/views" * "/home/god/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/bundler/gems/active_admin-c27b19fae6d4/app/views" * "/home/god/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/kaminari-core-1.2.1/app/views" * "/home/god/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/devise-4.7.3/app/views" * "/home/god/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actiontext-6.0.3.4/app/views" * "/home/god/.rbenv
/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionmailbox-6.0.3.4/app/views"
这是我的查看页面xml_parsing/app/views/xmls/index.html.erb
<h1>Welcome !</h1>
<p><%= @user %></p>
<%# View <%= link_to 'Bookmarks', xml_bookmarks_path %>
<div class="container alert alert-light">
<%# <% binding.pry %>
<%= link_to 'Create PDF document', xmls_path(@xml, :format => :pdf) %>
<%= form_tag(xmls_path, method: :get, class: "form-inline", role: 'search') do %>
<div class="input-group">
<%= text_field_tag :term, params[:term], placeholder: 'Search', class: 'form-control', id: 'search', autocomplete: :off %>
<div class="input-group-btn search-panel">
<%= submit_tag 'Search', name: nil, class: "btn btn-default", id:"search" %>
</div>
</div>
<% end %>
<br><br><br>
<% @xml.each do |x| %>
<table>
<thead>
<tr>
<th>Title</th>
<th>Data</th>
<%= submit_tag 'Bookmark', name: nil, class: "btn btn-default" , id: "bookmark"%><br><br>
</tr>
</thead>
<tbody id="myTable">
<tr>
<td>Name :</td>
<td><%= x.name %></td> </tr>
<tr>
<td>Citation:</td>
<td><%= x.citation %></td>
</tr>
<tr>
<td>Year:</td>
<td><%= x.year %></td>
</tr>
<tr>
<td>nominal app:</td>
<td><%= x.nominal_app %></td>
</tr>
<tr>
<td>nominal res:</td>
<td><%= x.nominal_res %></td>
</tr>
<tr>
<td>headnote:</td>
<td><%= x.headnote %></td>
</tr>
<tr>
<td>judgement:</td>
<td><%= x.judgement %></td>
</tr>
<tr>
<td>case no:</td>
<td><%= x.case_no %></td>
</tr>
<tr>
<td>justices:</td>
<td><%= x.justices %></td>
</tr>
<tr>
<td>case number:</td>
<td><%= x.case_number %></td>
</tr>
<tr>
<td>party details:</td>
<td><%= x.party_details %></td>
</tr>
<tr>
<td>petitioner advocates:</td>
<td><%= x.petitioner_advocates %></td>
</tr>
<tr>
<td>respondent advocates:</td>
<td><%= x.respondent_advocates %></td>
</tr>
<tr>
<td>judgement date:</td>
<td><%= x.judgement_date %></td>
</tr>
<tr>
<td>judgement object id:</td>
<td><%= x.judgement_object_id %></td>
</tr>
</tbody>
</table>
<% end %>
<script type="text/javascript">
$(document).on('turbolinks:load',function(){
var xmls = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/xmls/autocomplete?query=%QUERY',
wildcard: '%QUERY'
}
});
$("#search").typeahead(null, {
source: xmls
});
})
$(function() {
$("#bookmark").on("click", function(event) {
event.preventDefault();
$.ajax({
type: "POST",
url: "your_controller_url",
data: "your_form_data"
success: function(result) {
// Append the result to a table or list, $("list").append(result)
},
});
});
});
</script>
这是我的控制器
def index
# binding.pry
# binding.pry
@user = current_user.email
search = params[:term].present?
@xml = if search
Xml.search(search)
else
Xml.all
end
respond_to do |format|
format.html
format.pdf do
redirect_to pdf: "xml.pdf", # Excluding ".pdf" extension.
template: "xmls_controller/index.html.erb"
end
end
end
渲染或模板有问题吗
我认为 respond_to
pdf 中的控制器而不是 redirect_to
你应该使用 render
就像在邪恶的文档 pdf gem.
中一样
format.pdf do
render pdf: "file_name" # Excluding ".pdf" extension.
end
我想在rails中实现文件导出为pdf。但不是下载选项而是重定向到视图页面 http://localhost:3000/xmls?pdf=xml.pdf&template=xmls_controller%2Findex.html.erb
我使用了 render 但抛出错误,这就是我使用 redirect_to
的原因Template is missing
Missing template xmls_controller/index.html.erb with {:locale=>[:en], :formats=>[:pdf], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :arb, :jbuilder]}. Searched in: * "/home/god/Documents/xml_parsing/xml_parsing/app/views" * "/home/god/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/bundler/gems/active_admin-c27b19fae6d4/app/views" * "/home/god/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/kaminari-core-1.2.1/app/views" * "/home/god/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/devise-4.7.3/app/views" * "/home/god/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actiontext-6.0.3.4/app/views" * "/home/god/.rbenv
/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionmailbox-6.0.3.4/app/views"
这是我的查看页面xml_parsing/app/views/xmls/index.html.erb
<h1>Welcome !</h1>
<p><%= @user %></p>
<%# View <%= link_to 'Bookmarks', xml_bookmarks_path %>
<div class="container alert alert-light">
<%# <% binding.pry %>
<%= link_to 'Create PDF document', xmls_path(@xml, :format => :pdf) %>
<%= form_tag(xmls_path, method: :get, class: "form-inline", role: 'search') do %>
<div class="input-group">
<%= text_field_tag :term, params[:term], placeholder: 'Search', class: 'form-control', id: 'search', autocomplete: :off %>
<div class="input-group-btn search-panel">
<%= submit_tag 'Search', name: nil, class: "btn btn-default", id:"search" %>
</div>
</div>
<% end %>
<br><br><br>
<% @xml.each do |x| %>
<table>
<thead>
<tr>
<th>Title</th>
<th>Data</th>
<%= submit_tag 'Bookmark', name: nil, class: "btn btn-default" , id: "bookmark"%><br><br>
</tr>
</thead>
<tbody id="myTable">
<tr>
<td>Name :</td>
<td><%= x.name %></td> </tr>
<tr>
<td>Citation:</td>
<td><%= x.citation %></td>
</tr>
<tr>
<td>Year:</td>
<td><%= x.year %></td>
</tr>
<tr>
<td>nominal app:</td>
<td><%= x.nominal_app %></td>
</tr>
<tr>
<td>nominal res:</td>
<td><%= x.nominal_res %></td>
</tr>
<tr>
<td>headnote:</td>
<td><%= x.headnote %></td>
</tr>
<tr>
<td>judgement:</td>
<td><%= x.judgement %></td>
</tr>
<tr>
<td>case no:</td>
<td><%= x.case_no %></td>
</tr>
<tr>
<td>justices:</td>
<td><%= x.justices %></td>
</tr>
<tr>
<td>case number:</td>
<td><%= x.case_number %></td>
</tr>
<tr>
<td>party details:</td>
<td><%= x.party_details %></td>
</tr>
<tr>
<td>petitioner advocates:</td>
<td><%= x.petitioner_advocates %></td>
</tr>
<tr>
<td>respondent advocates:</td>
<td><%= x.respondent_advocates %></td>
</tr>
<tr>
<td>judgement date:</td>
<td><%= x.judgement_date %></td>
</tr>
<tr>
<td>judgement object id:</td>
<td><%= x.judgement_object_id %></td>
</tr>
</tbody>
</table>
<% end %>
<script type="text/javascript">
$(document).on('turbolinks:load',function(){
var xmls = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/xmls/autocomplete?query=%QUERY',
wildcard: '%QUERY'
}
});
$("#search").typeahead(null, {
source: xmls
});
})
$(function() {
$("#bookmark").on("click", function(event) {
event.preventDefault();
$.ajax({
type: "POST",
url: "your_controller_url",
data: "your_form_data"
success: function(result) {
// Append the result to a table or list, $("list").append(result)
},
});
});
});
</script>
这是我的控制器
def index
# binding.pry
# binding.pry
@user = current_user.email
search = params[:term].present?
@xml = if search
Xml.search(search)
else
Xml.all
end
respond_to do |format|
format.html
format.pdf do
redirect_to pdf: "xml.pdf", # Excluding ".pdf" extension.
template: "xmls_controller/index.html.erb"
end
end
end
渲染或模板有问题吗
我认为 respond_to
pdf 中的控制器而不是 redirect_to
你应该使用 render
就像在邪恶的文档 pdf gem.
format.pdf do
render pdf: "file_name" # Excluding ".pdf" extension.
end