Forum: Ruby on Rails form_for - over riding the controller that generates the for

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
09ca7bd1bc03a735ed913a9de3f4370b?d=identicon&s=25 Mindtonic (Guest)
on 2007-07-31 14:21
(Received via mailing list)
Hello,

I am trying to install my login and search forms as default parts of
the layout.  This is the code I am using:

<% form_for :user, :url => {:action => 'authenticate'} do |f| %>
  <p>Username:<br /><%= f.text_field :username, :size => 30 %></p>
  <p>Password:<br /><%= f.password_field :password, :size => 30 %></p>
  <%= submit_tag 'Login' %>
<% end %>

This is the form that is created:

  <form action="/pages/authenticate" method="post">
    <p>
      LOGIN <input id="user_username" name="user[username]" size="10"
type="text" />
      PASSWORD <input id="user_password" name="user[password]" size="10"
type="password" />
      <input name="commit" type="submit" value="Login" />
    </p>
  </form>

The form action is referring to the pages controller.  I need it to
refer to the accounts controller, which the same code does after
whenever permissions are not granted.  How can I tell form_for which
specific controller to reference?

Thanks!
09ca7bd1bc03a735ed913a9de3f4370b?d=identicon&s=25 Mindtonic (Guest)
on 2007-07-31 14:32
(Received via mailing list)
The answer turns out to be quite simple:

form_for :user, :url => {:action => 'authenticate', :controller =>
'account' }

<% form_for :user, :url => {:action => 'authenticate', :controller =>
'account' } do |f| %>
        <p>Username:<br /><%= f.text_field :username, :size => 30 %></
p>
        <p>Password:<br /><%= f.password_field :password, :size => 30
%></p>
        <%= submit_tag 'Login' %>
<% end %>
This topic is locked and can not be replied to.