views:

16

answers:

2

Hello,

I would like to create a login field everywhere on the top of my page, so I've add a :

in application.html.erb :

<%= render :partial => 'sessions/new' %>

in .../views/sessions/_new.html.erb

<%= form_tag do %>
  <div>
    <label for="name">Email :</label>
    <%= text_field_tag :name, params[:name] %>
    <label for="password">Mot de passe :</label>
    <%= password_field_tag :password, params[:password] %>
  </div>

  <div>
    <%= submit_tag "Connection" %>
  </div>
</fieldset>

<% end %>

But it's work only if I am in a sessions controller when I test it in my browser, I think that :

<%= submit_tag "Connection" %>

refers to his current controller (sessions) that's why it's doesn't work in ads/index for exemple but do its job in sessions/index.

What can I do ? Do I have to specify the controller in the submit_tag ?

Thanks a lot :)

A: 

You need to tell the form tag the url that the form should submit to. Maybe by default it submits to the current action or something? You should never rely on the default whatever it is.

Read the api http://railsbrain.com/api/rails-2.3.2/doc/index.html?a=M002551&amp;name=form_tag

oh and btw the submit tag is just a button, it doesn't have anything to do with why the form does or doesn't work. There's a lot of confusion among rails novices about forms - a lot of people don't really understand how forms work. Before using any rails helpers at all, i'd strongly recommend making your form in pure html. That way you will understand what is actually going on, and the form helpers will be just that, ie "things that help you to do something more quickly" rather than being these magical things that leave you totally clueless when they don't do what you expect.

Max Williams
Thanks :) I love you too
akam
A: 

You need to specify the controller but on the form_tag not the submit_tag

e.g. <%= form_tag :controller => 'sessions', :action => 'new' %>

mikej
Thanks you !I love U :)
akam