I have 2 controllers: Welcome (which handles the homepage) and Invitations (Which help people to create/manage invites). I am trying to have on the same welcome.html.erb both partials from Invitation view: _form.html.erb (for creating invitation) and _results.html.erb (to display the invites via Ajax on the same welcome.html.erb page).
I also have have create.js.erb in the Invitation's view folder.
The input work well but there is no live update. I still need to refresh the page. Does anyone know what i am doing wrong please?
_form.html.erb code is:
<h3 class="section_title"> Express meeting request IR </h3>
<div id="theform">
<%= simple_form_for invitation do |f| %>
<%= f.error_notification %>
<%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>
<%= f.label "Dest." %>
<%= f.collection_select(:guest_id, User.all, :id, :full_name, {}, class: "selectpicker", title: "Choose recipient", multiple: true, data: {style: "form-control", size: "200", width: "100%"}) %>
<br><br>
<%= f.input :event_id %>
<%= f.input :start %>
<%= f.input :title %>
<%= f.input :type_of_event %>
<%= f.label "Memo" %> <br>
<%= f.text_area :memo, as: :text, class: "text_area_iro", rows: 5 %>
<div class="form-actions">
<%= f.button :submit, class: "btn-custom"%>
</div>
<% end %>
</div>
_result.html.erb (certain header of the table removed) looks as:
<% @invitationsR.each do |invitation| %>
<tr>
<td><%= find_name(invitation.user_id) %></td>
<td><%= invitation.start %></td>
<td><%= TypeEvenement.find_by(id: invitation.type_of_event).type_name %> </td> </tr>
<% end %>
create.js.erb looks as:
$("#theform").html("<%= escape_javascript(render :partial => 'invitations/result', :locals => {:invitation => @invitation}) %>");
Welcome.html.erb looks like
<%= render :partial => 'invitations/form', :locals => {:invitation => Invitation.new} %>
<%= render :partial => 'invitations/result', :locals => {:invitations => @invitations} %>
The controller is as usual with plain new and create methods. The create method is as follows:
def create
@listmail = params[:invitation][:guest_id]
@listmail = @listmail.join(' ').split
@listmail.each do |v|
@invitation = current_user.invitations.build(invitation_params)
@invitation.guest_id = v
puts(v)
@invitation.save!
end
if @invitation.save
redirect_to invitations_path
else
render 'new'
end
end