LoginSignup
0
0

More than 1 year has passed since last update.

railsチュートリアル第八章 ログインフォーム

Posted at

ログインフォーム

ログインフォームのビューを整える。

<% provide(:title, "Log in") %>
<h1>Log in</h1>

<div class="row">
  <div class="col-md-6 col-md-offset-3">
    <%= form_with(url: login_path, scope: :session, local: true) do |f| %>
    <!--セッションの場合はリソースのスコープとそれに対応するURLを具体的に指定する必要-->
      <%= f.label :email %>
      <%= f.email_field :email, class: 'form-control' %>

      <%= f.label :password %>
      <%= f.password_field :password, class: 'form-control' %>

      <%= f.submit "Log in", class: "btn btn-primary" %>
    <% end %>

    <p>New user? <%= link_to "Sign up now!", signup_path %></p>
  </div>
</div>
 <form action="/login" accept-charset="UTF-8" method="post"><input type="hidden" name="authenticity_token" value="9t+########==" />
    <!--セッションの場合はリソースのスコープとそれに対応するURLを具体的に指定する必要-->
      <label for="session_email">Email</label>
      <input class="form-control" type="email" name="session[email]" id="session_email" />

      <label for="session_password">Password</label>
      <input class="form-control" type="password" name="session[password]" id="session_password" />

      <input type="submit" name="commit" value="Log in" class="btn btn-primary" data-disable-with="Log in" />
</form>

演習

1.リスト 8.4で定義したフォームで送信すると、Sessionsコントローラのcreateアクションに到達します。Railsはこれをどうやって実現しているでしょうか? 考えてみてください。ヒント:表 8.1とリスト 8.5の1行目に注目してください。
rails routesより

POST   /login(.:format)    sessions#create

送信するときにcreateアクションが使われるみたい。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0