1
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 5 years have passed since last update.

「params」のざっくりした説明

Last updated at Posted at 2018-09-17

params、ざっくりと説明してみる。
 
 
params、言ってみれば、**HTTPリクエストのPOSTメソッド1で送信したデータが格納されたハッシュ2**のこと。

あらかじめ、トップページ(/)にHTMLリクエストのPOSTメソッドが来たときの条件を決めておいたとして、name属性でキーの名前を指定すれば、

.erb
<form action="/" method="POST">
  <label>名前: <input type="text" name="target_name"></label>
  <input type="submit" value="送信"> 
</form>

<% name = params["target_name"] %>
<%= name %>

となり、フォームに入力したら、そのしたに入力した情報が出力される。

  1. POSTメソッドでの送信に限らない。詳しくはコメント欄で@scivolaさんが指摘してくださった内容を参照していただきたい。

  2. 取り出すときにハッシュ['キー']であるように見えたのでparamsをハッシュと見立てたが、じつはメソッドであるとのこと。こちらも、コメント欄での@scivolaさんの指摘を参照されたい。

1
0
2

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
1
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?