以下のindex.html.erbのソースコードの7行目で、ヘルパーメソッドmenu_link_toの第二引数に配列が指定されているのですが、その配列の中の:imageの意味がわからず困っています。
この配列の中の:newはnewアクションを意味し、@entryはモデルオブジェクトを意味しており全体としてオブジェクトでパスを表していることは理解しましたが、:imageはここではどのような意味・役割なのでしょうか?
また、33行目のlink_to "編集", edit_entry_image_path(@entry, image)における、imageについても意味・役割がよくわかりません。
:imageやimageが画像の追加や編集機能に必要な記述だということ以外はわからないので教えてください。よろしくお願いします。
<% @page_title = "ブログ記事の画像" %>
<h1><%= @page_title %></h1> <h2><%= @entry.title %></h2> <ul class="toolbar"> <%= menu_link_to "ブログ記事に戻る", @entry %> <%= menu_link_to "画像の追加", [:new, @entry, **:image**] %> </ul><% if @images.present? %>
<table class="list"> <thead> <tr> <th>番号</th> <th>画像</th> <th>代替テキスト</th> <th>操作</th> </tr> </thead> <tbody> <% @images.each_with_index do |image, index| %> <tr> <td><%= index + 1 %></td> <td> <%= image_tag image.data.variant(resize: "100x>"), alt: image.alt_text %> </td> <td> <%= image.alt_text %> </td> <td> <div> <%= link_to "編集", edit_entry_image_path(@entry, **image**) %> | <%= link_to "削除", entry_image_path(@entry, image), method: :delete, data: { confirm: "本当に削除しますか?" } %> </div> <div> <%= link_to_if index > 0, "上へ", move_higher_entry_image_path(@entry, image), method: :patch %> | <%= link_to_if index < @images.size - 1, "下へ", move_lower_entry_image_path(@entry, image), method: :patch %> </div> </td> </tr> <% end %> </tbody> </table> <% else %> <p>画像がありません。</p> <% end %>使用したテキストおよび該当するページ:インプレス出版 改訂4版 基礎 Ruby On Rails 463P
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/04/22 14:04