How can I have the recipient field default to specific users?

How can I have the recipient field default to specific users?

<strong>QUESTION: How can I have the recipient field, automatically filled out, with a user's username, for example, using the MailBoxer gem?</strong>

QUESTION: How can I have the recipient field, automatically filled out, with a user's username, for example, using the MailBoxer gem?

I have a user admin account, and I want to have the recipient field pre-filled out, when I click on a user (non admin) profile page, in the show.html.erb view.

Currently, the code used displays ALL users utilising the platform, whereas I want this specific form to only display the recipient.

I am using the mailboxer gem, and I have the subject and message field already pre-filled and working.

The code for the form, which is in the show.html.erb view:

<%= form_for :conversation, url: :conversations, html: { class: "" } do |f| %>

<div class="form-group"> <%= f.label :recipients %> <%= f.select(:recipients, User.all.collect {|p| [ p.username, p.id ] }, {}, { multiple: true , class: "chosen-select form-control", :data => {:placeholder => "Please type in a username to search for a user"}})%> </div>

<div class="form-group"> <%= f.label :subject %> <%= f.text_field :subject, placeholder: "Subject", class: "form-control", value: "Hi #{@user.username}! %> </div>

<div class="form-group"> <%= f.label :message %> <%= f.text_area :body, class: 'form-control',placeholder: "Type your message here", rows: 4, value:

"Hi #{@user.username}!

I am mailing you to tell you that [INSERT ITEM NAME] is in stock.

Please come down to receive the item. %> </div>

<%= f.submit "Send Message" %>

<% end %>


ruby-on-rails ruby

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Explain Ruby on rails MVC

Our Ruby on Rails Training will provide you to learn about Rails and web applications development with realty. Our Ruby on Rails Course also includes live sessions.

Pros & Cons you must know before using Ruby on Rails for your startup

Click here, free ruby on rails course videos for you. It shows you best way to complete Ruby certification. OnlineITGuru guides you towards easy Web script

Ruby on Rails Performance Tuning

Synchronises Assets between Rails and S3. Contribute to AssetSync/asset_sync development by creating an account on GitHub.

DoubleRenderError in Ruby on Rails

How do I solve the DoubleRenderError by using before_action.To practice my rails skills, I decided to make a website about events. It is a website mainly between organizations, who hold an event and volunteers, who join the event. Among all the problems I encountered, I want to share the DoubleRenderError because it bothered me for a long time and how I solve the problem.

Live Updates in Ruby on Rails with ActionCable Feature

There are times when one as a Ruby on Rails developer wants to implement a real-time feature, like a chat application, and after digging a bit you find a framework's feature named ActionCable, sounds new and scary, right? Fear not, I'll try to explain it as simple as possible so that at the end of this article you'll feel comfortable with the subject.