如何让收件人字段默认为特定用户?
How can I have the recipient field default to specific users?
问题:如何让收件人字段自动填写用户的用户名,例如,使用 MailBoxer gem?
我有一个用户管理员帐户,当我在 show.html.erb 视图中单击用户(非管理员)个人资料页面时,我希望预先填写收件人字段。
目前,使用的代码显示所有使用该平台的用户,而我希望此特定表单仅显示收件人。
我正在使用邮箱 gem,我已经预先填写了主题和消息字段并且可以使用。
表单的代码,在 show.html.erb 视图中:
<%= 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 %>
您可以使用属性 selected :selected => @user.id(根据您上面的代码,您有 @user)
<div class="form-group">
<%= f.label :recipients %>
<%= f.select(:recipients, User.all.collect {|p| [ p.username, p.id ] }, {}, , { :selected => @user.id, multiple: true , class: "chosen-select form-control", :data => {:placeholder => "Please type in a username to search for a user"}})%>
</div>
问题:如何让收件人字段自动填写用户的用户名,例如,使用 MailBoxer gem?
我有一个用户管理员帐户,当我在 show.html.erb 视图中单击用户(非管理员)个人资料页面时,我希望预先填写收件人字段。
目前,使用的代码显示所有使用该平台的用户,而我希望此特定表单仅显示收件人。
我正在使用邮箱 gem,我已经预先填写了主题和消息字段并且可以使用。
表单的代码,在 show.html.erb 视图中:
<%= 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 %>
您可以使用属性 selected :selected => @user.id(根据您上面的代码,您有 @user)
<div class="form-group">
<%= f.label :recipients %>
<%= f.select(:recipients, User.all.collect {|p| [ p.username, p.id ] }, {}, , { :selected => @user.id, multiple: true , class: "chosen-select form-control", :data => {:placeholder => "Please type in a username to search for a user"}})%>
</div>