在app / controllers / fw_exports_controller.rb中,我有:
def import_spreadsheet
@followeds = Followed.all.order(:screen_name)
@import_spreadsheet = FwExport.new
render partial: 'fw_exports/import_spreadsheet'
end
在app / views / layouts / application.html.slim中,我有:
doctype html
html
head
meta content=("text/html; charset=UTF-8") http-equiv="Content-Type" /
meta content="width=device-width, initial-scale=1.0" name="viewport" /
title= content_for?(:title) ? yield(:title) : t('project_name')
meta content=("#{content_for?(:description) ? yield(:description) : t('project_name')}") name="description" /
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true
= javascript_include_tag 'application', 'data-turbolinks-track' => true
= csrf_meta_tags
body
header
= render 'layouts/navigation'
main role="main"
= render 'layouts/messages'
= yield
= render "layouts/footer"
在app / views / layouts / _navigation.html.slim中,我有:
nav.navbar.navbar-default role="navigation"
.container
.navbar-header
a.navbar-brand href="#"
= t('parnassus_tools_home')
.navbar-left
ul.nav.navbar-nav
li
a
= link_to t('menus.upload_file'), import_spreadsheet_path
在app / views / fw_exports / _import_spreadsheet.html.slim中,我有:
.container
h1
= t('fw_exports.choose_file_to_upload')
= form_tag process_imported_spreadsheet_path, html: { multipart: true }
.form-group
= file_field_tag :import_file
- if !@followeds[0].nil?
.form-group
= select_tag "followed_id", options_from_collection_for_select(@followeds, "id", "screen_name", "1")
.form_group
.sr-only
= label_tag t('fw_exports.screen_name_to_add')
= text_field_tag :screen_name_addition, placeholder: t('fw_exports.screen_name_to_add')
= button_tag(type: 'submit', class: "btn btn-primary") do
i.icon-ok.icon-white
= t('fw_exports.import')
在app / views / landings / index.html.slim中,我有(这是主页):
h1 Home Page
p test text
这是我在主页上看到的内容:
但是,当我点击主页上的“上传文件”菜单项时,我看到的是:
为什么应用程序布局不适用于表单?
答案 0 :(得分:2)
您需要渲染为模板而不是部分渲染。首先,创建一个视图模板:
应用/视图/ fw_spreadsheet / import_spreadsheet.html.slim 强>
= render 'fw_exports/import_spreadsheet_form'
接下来,通过将 app / views / fw_spreadsheet / _import_spreadsheet.html.slim 的名称更改为 app / views / fw_spreadsheet / _import_spreadsheet_form.html.slim 来重命名您的部分内容
最后,按如下方式修改您的控制器:
应用/控制器/ fw_exports_controller.rb 强>
def import_spreadsheet
@followeds = Followed.all.order(:screen_name)
@import_spreadsheet = FwExport.new
render 'fw_exports/import_spreadsheet'
end