Ruby on Rails user login form in main layout
Posted
by Jimmy
on Stack Overflow
See other posts from Stack Overflow
or by Jimmy
Published on 2010-06-08T14:48:32Z
Indexed on
2010/06/08
14:52 UTC
Read the original article
Hit count: 222
ruby-on-rails
|routing
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?
© Stack Overflow or respective owner