EastsideDev
EastsideDev

Reputation: 6639

Application layout not applied to form

In app/controllers/fw_exports_controller.rb, I have:

def import_spreadsheet
  @followeds = Followed.all.order(:screen_name)
  @import_spreadsheet = FwExport.new
  render partial: 'fw_exports/import_spreadsheet'
end

In app/views/layouts/application.html.slim, I have:

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"

In app/views/layouts/_navigation.html.slim, I have:

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

In app/views/fw_exports/_import_spreadsheet.html.slim, I have:

.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')    

In app/views/landings/index.html.slim, I have (this is the home page):

h1 Home Page
p test text

Here's what I see when I am on the home page:

Home Page Image

But when I click on the Upload File menu item, from the home page, here's what I see:

Upload File Form

Why isn't the application layout applied to the form?

Upvotes: 1

Views: 52

Answers (1)

Tom Aranda
Tom Aranda

Reputation: 6036

You will need to render as a template and not as a partial. First, create a view template:

app/views/fw_spreadsheet/import_spreadsheet.html.slim

= render 'fw_exports/import_spreadsheet_form'

Next, rename your partial by changing the name of app/views/fw_spreadsheet/_import_spreadsheet.html.slim to app/views/fw_spreadsheet/_import_spreadsheet_form.html.slim

Finally, modify your controller as follows:

app/controllers/fw_exports_controller.rb

def import_spreadsheet
  @followeds = Followed.all.order(:screen_name)
  @import_spreadsheet = FwExport.new
  render 'fw_exports/import_spreadsheet'
end

Upvotes: 2

Related Questions