In my database, I have a table called "whatsup" and another one called "users". The structure is set up in such a way that each whatsup belongs to a user. Users can create new whatsups using Ajax, as shown below:
$("#chat").append("<%= j render(@whatsup) %>");
$("#new_whatsup")[0].reset();
The newly created whatsups are displayed above the form like this:
<ul id="chat">
<%= render @whatsups %>
</ul>
<%= form_for Whatsup.new, remote: true do |f| %>
<%= f.text_field :details%>
<%= f.submit "Send" %>
<% end %>
In my controller, the declaration for @whatsups looks like this:
@whatsups = current_user.whatsups.all(:limit => 1, :order => 'created_at DESC')
This setup ensures that only one whatsup is displayed at a time.
My goal is to reload the partial @whatsups immediately after the form is submitted, without refreshing the entire page. This way, the newly created whatsups will be automatically shown.