困っていること
お気に入り機能を実装したいけれど,content_idをうまく取得できない
controller
def create
debugger
@user = current_user @content = Content.find(params[:id]) @clip = Clip.create(user_id: @user_id, content_id: @content.id)
if @clip.save
redirect_to root_path
else
render "home/top"
end
end
view
<% if @result.nil? %>
<% @content.each do |c| %>
<div class="lang"> <div> <%= link_to "このイベントをクリップ", add_content_path(@content.ids), method: :post %> </div> <h2 class ="content_title"><%= link_to c.title, message_path(c.id) %></h2> </br> <p class ="content_description"> <%= c.description %> <% end %> </p> <% else %> <%= @result %> <%end%> </div><div class="image"> <% if c.picture? %> <%= image_tag c.picture.url, :class => "choice_image"%> <% else %> <%= image_tag "kuma.png", size:'90x90', :class => "choice_image"%> <% end %> </div>
コンテンツのIDを紐づけて保存したいのですが、 rails sで見ると rollback transactionされてしまいます。
ユーザーはログインできているので、user_idは取得できていると思います。
debugg情報を見ると、id: 5/4/3/2/1を取得しているため個別にIDが取得できていないと思います。
アドバイスをいただけると幸いです。よろしくお願いいたします
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/17 03:08