1

I have this form:

= simple_form_for :login, url: sessions_path, method: :post, role: "form", class: "form-horizontal" do |f|
  = f.input :email
  = f.input :password
  = f.input :remember_me, as: :boolean, label: false, inline_label: "Stay connected"
  = f.submit "Login", class: "btn btn-primary"
  = link_to 'Forgot Password?', new_password_reset_path

After a bit of Bootstrap styling:

.panel.panel-primary
  .panel-heading
    %p
      the login form
  .panel-body
    = simple_form_for :login, url: sessions_path, method: :post, role: "form", class: "form-horizontal" do |f|
      = f.input :email
      = f.input :password
      = f.input :remember_me, as: :boolean, label: false, inline_label: "Stay connected"
  .panel-footer
    = f.submit "Login", class: "btn btn-primary"
    = link_to 'Forgot Password?', new_password_reset_path

I get undefined variable or method f, what should be done to get it working? I tried nesting the .panel-footer inside the form, it works but I didn't get the proper styling.

mtkcs
  • 1,696
  • 14
  • 27

2 Answers2

4

Now, the submit button is out of your form block. So you can wrap all the things into the form block like the following.

     = simple_form_for :login, url: sessions_path, method: :post, role: "form", class: "form-horizontal" do |f|    
      .panel.panel-primary
          .panel-heading
            %p
              the login form
          .panel-body
            = f.input :email
            = f.input :password
            = f.input :remember_me, as: :boolean, label: false, inline_label: "Stay connected"
          .panel-footer
            = f.submit "Login", class: "btn btn-primary"
            = link_to 'Forgot Password?', new_password_reset_path
Bachan Smruty
  • 5,686
  • 1
  • 18
  • 23
  • 1
    You have to put the panelS (plural) in the form, that makes complete sense! Thank You for posting this Answer, I had this exact issue and it was driving me nuts. Anytime I tried to put the submit button into the panel-footer the f. on the form acted like it lost connection to the form itself. THANK YOU VERY MUCH @Bachan Smruty !! – Scott Milella Oct 06 '22 at 19:14
1

Of course, that is completely dependent on how your css looks like, but what you could do is something like

= simple_form_for :login, url: sessions_path, method: :post, role: "form", class: "form-horizontal" do |f|
  .panel-body
    = f.input :email
    = f.input :password
    = f.input :remember_me, as: :boolean, label: false, inline_label: "Stay connected"
  .panel-footer
    = f.submit "Login", class: "btn btn-primary"
    = link_to 'Forgot Password?', new_password_reset_path

But it is not an issue with HAML, with erb you would have the same exception

Fer
  • 3,247
  • 1
  • 22
  • 33