Using Mailboxer to create internal messaging system where user can message another user from a listing of basic profiles (for those who have created them).
The index that shows the list of basic_profiles (experts) is showing, but the link to the create a new message is not passing parameters to create a new message.
Here's the Experts index that lists basic profiles and where the link is for the current user to send a new message to the user who's basic profile it is:
<div style="margin-top:100px;">
<h3>Experts</h3>
<% BasicProfile.all.each do |basic_profile| %>
<div>
<p style="padding-top:20px;"> <img src="<%= basic_profile.picture_url %>"
style="float: left;margin: 5px;">
<span style="font-size:14px;"><b>
<%= basic_profile.first_name %> <%= basic_profile.last_name %></b></span></><br>
<b><i><%= basic_profile.headline %></i></b><br>
<%= basic_profile.location %><br>
<%= basic_profile.industry %><br>
<%= basic_profile.specialties %><br>
<%= button_to "Send a message", new_message_path(@user) %></p>
</div>
<% end %>
</div>
Here's the Experts Controller:
class ExpertsController < ApplicationController
def index
@basic_profiles = BasicProfile.all
@user = User.all
end
end
Here's the Messages Controller:
class MessagesController < ApplicationController
# GET /message/new
def new
@user = User.find_by_email(params[:user])
@message = current_user.messages.new
end
# POST /message/create
def create
@recipient = User.find_by_email(params[:user])
current_user.send_message(@recipient, params[:body], params[:subject])
flash[:notice] = "Message has been sent!"
redirect_to :conversations
end
end
Here's the view for a new message:
<div style="margin-top:200px;">
Send a message to
<%= @user.email %>
<%= form_tag({controller: "messages", action: "create"}, method: :post) do %>
<%= label_tag :subject %>
<%= text_field_tag :subject %>
<%= label :body, "Message text" %>
<%= text_area_tag :body %>
<%= hidden_field_tag(:user, "#{@user.id}") %>
<%= submit_tag 'Send message', class: "btn btn-primary" %>
<% end %>
</div>
Here's what is in routes for messages:
resources :messages do
collection do
post 'new/:user', to: 'messages#create'
end
member do
post :reply
post :trash
post :untrash
post :new
end
Devise is being used.
I am wondering why params are not being passed to the view for a new message.