0
0

More than 3 years have passed since last update.

railsを使ってアプリを作る3

Posted at

詳細ページ等のid付きのページの作成と表示

mvcの作成

urlが/details/1みたいにする場合は、ルーティングの書き方を
get "details/:id" => "details#show
にする

detailsコントローラーにshowメソッドを作成する

show.html.erbのファイルを作成する

idの取得と利用方法

コントローラーでparams[:id] で取得する
取得した値を
@id = params[:id]とし、viewで<%= @id %>と書いて使う

画面に置くリンクはこんな感じ
<% @details.each do |detail| %>
  <%=link_to (animal.content,"/animal/#{detail.id}")%>
<% end %>

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