A
A
arlovski2015-02-27 23:56:43
Ruby on Rails
arlovski, 2015-02-27 23:56:43

rails. Why is authenticity_token empty?

Good evening, I ran into the same problem. On page 2 POST forms, both generated via form_tag

<div class="col-md-4 col-md-offset-4 col-lg-4 col-lg-offset-4">
  <!-- Nav tabs -->
  <ul class="nav nav-pills" role="tablist">
    <li role="presentation" class="active"><a href="#login" aria-controls="login" role="pill" data-toggle="pill" class="nav-pill">Login</a></li>
    <li role="presentation"><a href="#register" aria-controls="login" role="pill" data-toggle="pill" class="nav-pill">Register</a></li>
  </ul>

  <!-- Tab panes -->
  <div class="tab-content top20">
    <div role="tabpanel" class="tab-pane active" id="login">
        <%= form_for "login/sign_in", method: "post", id: 'loginForm' do %>
            <div class="form-group">
                <%= label_tag :username, "Username" %>
                <%= text_field_tag :log_username, nil, class: 'form-control', placeholder: 'Enter username' %>
            </div>
            <div class="form-group">
                <%= label_tag :log_password, "Password" %>
                <%= password_field_tag :log_password, nil, class: 'form-control', placeholder: 'Password' %>
            </div>
          <%= submit_tag "Sign in", class: "btn btn-black" %>
        <% end %>
    </div>
    <div role="tabpanel" class="tab-pane" id="register">
        <%= form_tag "login/sign_up", method: "post", id: 'registerForm' do %>
            <div class="form-group">
                <%= label_tag "data[username]", "Username" %>
                <%= text_field_tag "data[username]", nil, class: 'form-control', placeholder: 'Enter username' %>
            </div>
            <div class="form-group">
                <%= label_tag "data[password]", "Password" %>
                <%= password_field_tag "data[password]", nil, class: 'form-control', placeholder: 'Password' %>
            </div>
            <div class="form-group">
                <%= label_tag "data[blog_title]", "Blog title" %>
                <%= text_field_tag "data[blog_title]", nil, class: 'form-control', placeholder: 'Blog title' %>
            </div>
          <%= submit_tag "Sign up", class: "btn btn-black" %>
        <% end %>
    </div>
  </div>

</div>

but as a result, the token is generated normally for the first form:
<form accept-charset="UTF-8" action="login/sign_in" method="post">
  <div style="display:none">
    <input name="utf8" type="hidden" value="✓">
    <input name="authenticity_token" type="hidden" value="arBY8Sf/5VsqeU2eqU8Cy9Ac2jnB9clmnCzgResOgiU=">
  </div>

and the second one is empty for some reason:
<form accept-charset="UTF-8" action="login/sign_up" method="post">
  <div style="display:none">
    <input name="utf8" type="hidden" value="">
    <input name="authenticity_token" type="hidden" value="">
  </div>

what is the problem?
thanks for the answer.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
arlovski, 2015-02-28
@arlovski

yes, bootstrap's tabchange resets the value of all inputs. sorry for the wrong question

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question