ツイッターでいうところのリツイート機能的なものを作っています。
noteコントローラーのshowにnoteモデルのデータを表示しており、同ビュー内にそれに対する別のコントローラーretweetコントローラーのnewをレンダー表示して、そのノートに対して投稿できるようにしています。
ruby
1Note#show の view 2 3<h2><%= @note.title %></h2> 4<p><strong><%= @note.language %> <span class="level">Level</span></strong><%= level_tag @note.level %></p> 5<strong>Detail</strong> 6<p class="text-primary"><%= @note.detail %></p> 7<strong>Exam</strong> 8<p><%= @note.body %></p> 9 10<%= render template: "retweets/new" %>
modelは、retweetモデルに、user_idとnote_id,bodyを持たせています。
retweetコントローラーのcreateアクションにはdeviseを使用しているのでcurrent_user.retweets.buildでユーザーidを自動的に紐づけており、これで、user_idはセットできます。
しかし、retweetモデルの:note_idに、noteコントローラーのshowで表示していたnote_idを渡す方法が分かりません。
よろしくお願いします。
ruby
1class NotesController < ApplicationController 2 def show 3 @retweet = retweet.new 4 end 5end 6 7class RetweetController < ApplicationController 8 def create 9 @retweet = current_user.retweets.build(retweet_params) 10 @retweet.save 11 end 12end
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。