こんにちは、railsをやっていて書いたメッセージを他のユーザーに送れるようにしたいのですが、メッセージを作成する画面にメッセージと誰に送るかという選択ボックスを作成して送信したいです。どのようにすればいいでしょうか?
試して見たのですがうまく行きませんでした```rails
コード
posts.show.html.erb
<div class="container"> <h1 class="form-heading">投稿する</h1> <%= form_for("/posts/create") do |f| %> <div class="form"> <div class="form-body"> <%= f.text_field :text %> <%= f.submit %> <%= f.collection_select :user_id, User.all, :id, :name, :prompt => true %> <input type="submit" value="投稿"> </div> </div> <% end %> </div> </div> ```rails コード def new @post = Post.new end def create @post = Post.new( content: params[:content], user_id: @current_user.id ) if @post.save flash[:notice] = "投稿を作成しました" redirect_to("/posts/index") else render("posts/new") end end よろしくお願いします。
あなたの回答
tips
プレビュー