0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

railsを使ってアプリを作る 登録編

Last updated at Posted at 2021-02-24

データベースにデータを登録####

ルーティングの作成#####

ルーティングに登録する時はpostで登録する
post "animals/create" => "animals#create"

viewの作成#####

送りたい内容を
<%= form_tag "/animals/create" do %>

<% end %>
で囲む

コントローラーの作成#####

viewからのデータを取得する
view = Animal.new(name: params[:name])
view.save

登録が完了したら、別ページに遷移させる(リダイレクト)
redirect_to "/animals/index"

get と post#####

get
 getはデータベースを変更しないアクション
post
 postはデータベースを変更するアクション
 postで登録する時は、フォームで入力した値をコントローラーで受け取る時に使うらしい
 なので、削除する時はデータが変更されるかPostになる

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?