わからないこと
コンテンツの作成ページとコンテンツ表示ページを一緒のページにしたいのですが方法がわかりません。
content一覧ページから特定の(content/:id)などのページを開きその画面でコンテンツに紐づいたmessageを作成し同じページに表示したいです。
その際のcontrollerの記述方法なのですが下記 記述です。
controller
class MessagesController < ApplicationController
before_action :logged_in_user, only: [:show, :create]
def show
@message = Message.new
@content = Content.find(params[:id])
end
def create
content = Content.find_by(params[:id])
@message = content.messages.build(message_params)
if @message.save
redirect_to "/messages/show"
else
render "/contents/show"
end
end
private
def message_params
params.require(:message).permit(:talk)
end
end
view
<div class="row"> <div class="col-md-4 col-md-offset-4"> <%= form_for(@message) do |f| %></div><%= f.label :喋ってみよう %> <%= f.text_area :talk, class: 'form-control'%> <%= f.submit "送信", class: "btn btn-success btn-sm" %> <% end %> </div>
この下にcontent.messagesを出力したい
@message.each do |msg|
....
....
end
上記のようにしたいのですがcontrollerでのデータの取得ができないです。(記述方法が分からない)
もしお分かりになる方がいれば、実装可能なのかともしわかれば記述方法も教えていただきたいです。
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/17 03:11