Ruby on Rails user login form in main layout
- by Jimmy
Hey guys I have a simple ror application for some demo stuff.
I am running into a problem with trying to move my login form from the users controller and just have it displayed in the main navigation so that a user can easily log in from anywhere.
The problem is the form doesn't generate the correct action for the html form. Ruby code:
<% form_for(url_for(:action => 'login'), :method => 'post') do |f| %>
<li><%= f.text_field("username") %></li>
<li><%= f.password_field("password") %></li>
<li><%= submit_tag("Login")%></li>
<% end %>
The problem is depending on the controller I am currently in this generates HTML actions like
<form action="/home" method="post">...</form>
when it should be generating HTML like so
<form action="/login" method="post">...</form>
I know I could simply do an HTML form here but I want to keep things as easy to maintain as possible.
Any help?