0
0

More than 1 year has passed since last update.

form_forにおけるsubmitの役割について

Last updated at Posted at 2022-02-24
<%= form_for @post do |f| %>
  <div class="field">
    <%= f.label :body %>
    <%= f.text_field :body, :size => 140 %>
  </div>
  <%= f.submit "投稿する" %>
<% end %>

におけるf.submitの役割は
@postの中身がPost.new(空の箱)の場合はcreateアクションに遷移する。
投稿内容を書き換えたい場合、
@postの中身を書き換えることになり、中身はPost.newではないので、その場合はupdateアクションに遷移する仕組みとなっている。

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