Form tag not showing up in haml file

2019-07-08 10:39发布

问题:

I'm trying to get a form inside a modal. Everything after the form tag shows up, but not the actual form tag there for can't be submitted. I am using the same form in other pages and it does work except here.

  AdGroups/edit.html.haml
   %div(id="openModal" class="modalDialog")
    %div
        %a(href="#close" title="Close" class="close")
        %div
        = form_tag car_path, :url => {:controller => 'cars', :action => 'create'}, :html => {:multipart => true,:id =>'car-form'} do |f|
            %div(class="control-group")
                = label_tag             "Year"
                %br
                = text_field_tag    "year"
            %br

            %div(class="control-group")
                = label_tag             "make"
                %br
                %select{ :name => "make", :class => "chosen" }
                    - @makes.each do |m|
                        %option{:value => m.id}= "#{m.name}"
            %br

            %div(class="control-group")
                = label_tag             "Model"
                %br
                = text_field_tag    "model"
            %br

            %div(class="control-group")
                = label_tag             "Trim"
                %br
                = text_field_tag    "trim"
            %br

            %div(class="control-group")
                = label_tag             "Car Image(s)"
                %br
                = file_field_tag    "files[]"
            %br


= submit_tag

When I inspect the form rather than the form tag it has an input tag. Any idea why?

<div class="modalDialog" id="openModal">
    <div>
      <a class="close" href="#close" title="Close"></a>
      <div></div>
      <input name="utf8" type="hidden" value="✓"><input type="hidden" name="authenticity_token" value="fc2o2n0JJlcMISfYQACsF0mNSrVkKnoa37eF2dDrGPPIu9CnJVVaNFz3drg8dAoOf1pm>

回答1:

This might take a few tries...

It looks like your form_tag might be wrong. Try:

= form_tag cars_path, multipart: true, id: 'car-form' do

Can you try doing just this (to see if you can get an empty form to render):

#openModal.modalDialog
  = form_tag cars_path, multipart: true, id: 'car-form' do
    foo

Make sure you're using cars_path and not car_path.