私はレールの初心者であり、いくつかのガイダンスを本当に感謝しています!
これが私の最初のビューの Link_to です。
<%= link_to micropost.user.name, micropost.user %> | <%= link_to "Send Message", new_conversation_path( target: micropost.user.name, reason: micropost.c1 ) %>
そして、ここに私の会話コントローラーがあります:
def new
@target = params[:target]
@reason = params[:reason]
end
def create
recipient_names = conversation_params(:recipients).split(',')
recipients = User.where(name: recipient_names).all
conversation = current_user.
send_message(recipients, *conversation_params(:body, :subject)).conversation
redirect_to conversation
end
ご覧のとおり、メールボックスの gem を使用しているため、会話モデルはありません。
最後に、2 番目のビューでのフォームは次のとおりです。
<%= simple_form_for :conversation, url: :conversations do |f| %>
<%= f.input :recipients, @target %>
<%= f.input :subject, @reason %>
<%= f.input :body %>
<div class="form-actions">
<%= f.button :submit, class: 'btn-primary' %>
<%= submit_tag 'Cancel', type: :reset, class: 'btn btn-danger' %>
</div>
<% end %>
ユーザーがメッセージ送信リンクをクリックしたときに、会話フォームに受信者の名前とマイクロポストの件名が自動的に事前設定されるようにします。
よろしくお願いします。