htmlファイルで他のコンロトーラーのアクションを呼び出すためにリンクを設定する方法を探しています。
Routing Error
No route matches [GET] "/product/279/enrty/:id"とエラーが出てしまいました。私は"/top/enrty/:id"と設定したかったです。
productsファイルのshow.html.erbに
Ruby
1> <div id="main_cnt_wrapper"> 2> <div id="yjContentsBody"> 3> <div class="yjContainer"> 4> <span class="yjGuid"><a id="yjContentsStart" name="yjContentsStart"></a><img alt="ここから本文です" height="1" src="http://i.yimg.jp/yui/jp/tmpl/1.1.0/audionav.gif" width="1"></span> 5> <div id="yjMain"> 6> <article class="section"> 7> <div class="container"> 8> <header class="header header--section"> 9> <h2 class="text-middle"> 10> <i class="icon-movie color-gray-light"></i><%= @product.title %> 11> </h2> 12> </header> 13> <p style="text-align: center"> 14> <img src="<%= @product.image_url %>" alt="<%= @product.title %>"> 15> </p> 16> <div style="text-align: right"> 17> <a href="/enrty/<%= @product.id %>">この作品を投稿する</a> ←←ここが重要 18> </div> 19> <header class="header header--section"> 20> <h2 class="text-middle"> 21> <i class="icon-movie color-gray-light"></i>みんなのレビュー 22> </h2> 23> </header> 24> <ul style="padding: 0"> 25> <% @product.reviews.each do |review| %> 26> <li style="border-bottom: dotted 1px"> 27> <div class="thumbnail__caption"> 28> <h3 class="text-xsmall text-overflow" title="<%= review.user.nickname %>"> 29> <%= review.user.nickname %><small 2014=""></small> 30> </h3> 31> <p class="text-small"> 32> <span class="rating-star"><i class="star-actived rate-<%= review.rate %>0"></i></span> 33> </p> 34> <p> 35> <%= review.review %> 36> </p> 37> </div> 38> </li> 39> <% end %> 40> </ul> 41> </div> 42> </article> 43> </div> 44> <div id="yjSub">
と記載して、リンクの部分が"localhost3000/top/enrty/:id"となるように設定したいです。
このような場合はどうゆうメソットを使えば良いのでしょうか?
ちなみにtop_controller.rbには
Ruby
1class TopController < ApplicationController 2 3 def entry 4 @product = Product.find_by(params[:id]) 5 end 6 7 def post 8 Review.create(nickname:current_user.nickname, product_id:params[:id], rate:create_params[:rate], review:create_params[:review]) 9 redirect_to action: :index 10 end 11 12end 13 14 15
と記載しました。
あなたの回答
tips
プレビュー